List directories recursively in powershell

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 
+5
source share
1 answer

In PowerShell, dir is an alias for the Get-ChildItem cmdlet.

Use it with the -Recurse parameter to recursively represent child elements:

 Get-ChildItem -Recurse 

If you only need directories, not files, use the -Directory switch:

 Get-ChildItem -Recurse -Directory 

The -Directory switch -Directory introduced for the file system provider in version 3.0.

For PowerShell 2.0, filter the PSIsContainer property:

 Get-ChildItem -Recurse |Where-Object {$_.PSIsContainer} 

(PowerShell aliases support parameter resolution, so Get-ChildItem can replace Get-ChildItem with dir in all the examples above)

+10
source

Source: https://habr.com/ru/post/1264688/


All Articles