How would I use powershell to count the number of files and the number of folders under a folder, emulating the Windows "properties" of that folder?
(get-childitem -recurse).count
returns the total object count (sum of folder and file counts), and
(gci -rec | where { $_.PSIsContainer }).count
returns the number of folders. But is there a way to count both folders and files in a single command without traversing the filesystem twice? I assume it's possible to write procedural powershell code with named variables and loops, but that doesn't seem like the normal way of using it.
And on a related topic, http://technet.microsoft.com/en-us/library/ee692796.aspx describes two ways of getting a list of filenames:
Get-ChildItem C:\Scripts | Select-Object Name
and
Get-ChildItem C:\Scripts -name
The author claims they are equivalent, but with -recurse the first returns only filenames while the second returns the full path. Is there a way to get Select-Object to return a full path so that these two commands generate the same output? (A random stab at Select-Object Path
produced blank lines, not paths.)
gci -rec -name
gci -rec | Select-Object xxx?