Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively list directories in powershell [duplicate]

Tags:

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 
like image 335
Snowcrash Avatar asked Feb 24 '17 14:02

Snowcrash


People also ask

How do I copy a directory in PowerShell recursively?

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.

What is the command to display a directory listing recursively PowerShell?

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.

How do I list all directories in PowerShell?

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.

Does xcopy work in PowerShell?

xcopy is the windows command. It works with both PowerShell and cmd as well because it is a system32 utility command.


1 Answers

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)

like image 188
Mathias R. Jessen Avatar answered Sep 28 '22 18:09

Mathias R. Jessen