How do you recursively list directories in Powershell?
I tried dir /S
but no luck:
PS C:\Users\snowcrash> dir /S dir : Cannot find path 'C:\S' because it does not exist. At line:1 char:1 + dir /S + ~~~~~~ + CategoryInfo : ObjectNotFound: (C:\S:String) [Get-ChildItem], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Use Copy-Item Command to Copy Files Recursively in PowerShell. We usually run into situations where we have many subfolders in the parent folder, which files we'd like to copy over. Using the -Recurse parameter on Copy-Item will look in each subfolder and copy all files and folders in each recursively.
Use dir Cmdlet With -Recurse Switch in PowerShell to Search Files Recursively. The dir cmdlet is an alias for the Get-ChildItem . It also displays a list of files and directories on the specific location.
On a Windows computer from PowerShell or cmd.exe, you can display a graphical view of a directory structure with the tree.com command. To get a list of directories, use the Directory parameter or the Attributes parameter with the Directory property. You can use the Recurse parameter with Directory.
xcopy is the windows command. It works with both PowerShell and cmd as well because it is a system32 utility command.
In PowerShell, dir
is an alias for the Get-ChildItem
cmdlet.
Use it with the -Recurse
parameter to list child items recursively:
Get-ChildItem -Recurse
If you only want directories, and not files, use the -Directory
switch:
Get-ChildItem -Recurse -Directory
The -Directory
switch is introduced for the file system provider in version 3.0.
For PowerShell 2.0, filter on the PSIsContainer
property:
Get-ChildItem -Recurse |Where-Object {$_.PSIsContainer}
(PowerShell aliases support parameter resolution, so in all examples above, Get-ChildItem
can be replaced with dir
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With