have Powershell get-childitem return files only
I'd like to use get-childitem recursively, but only have it return files not directories. The best solution I have just doesn't seem natural:
gci . *.* -rec | where { $_.GetType().Name -eq "FileInfo" }
Solution 1:
Try this:
gci . *.* -rec | where { ! $_.PSIsContainer }
Solution 2:
In Powershell 3.0, it is simpler,
gci -Directory #List only directories
gci -File #List only files
This is even shorter,
gci -ad # alias for -Directory
gci -af # alias for -File