How do I get only directories using Get-ChildItem?

后端 未结 15 1413
北海茫月
北海茫月 2020-11-29 16:30

I\'m using PowerShell 2.0 and I want to pipe out all the subdirectories of a certain path. The following command outputs all files and directories, but I can\'t figure out h

15条回答
  •  旧时难觅i
    2020-11-29 17:02

    From PowerShell v2 and newer (k represents the folder you are beginning your search at):

    Get-ChildItem $Path -attributes D -Recurse
    

    If you just want folder names only, and nothing else, use this:

    Get-ChildItem $Path -Name -attributes D -Recurse
    

    If you are looking for a specific folder, you could use the following. In this case, I am looking for a folder called myFolder:

    Get-ChildItem $Path -attributes D -Recurse -include "myFolder"
    

提交回复
热议问题