我使用的是PowerShell 2.0,我想通过管道输出某个路径的所有子目录。下面的命令输出所有的文件和目录,但是我不知道如何过滤掉这些文件。
Get-ChildItem c:\mypath -Recurse
我尝试过使用$_.Attributes
来获取属性,但是我不知道如何构造一个System.IO.FileAttributes
的文本实例来与之进行比较。在cmd.exe
中是这样的
dir /b /ad /s
发布于 2013-01-25 05:14:44
在PowerShell 3.0中,它更简单:
Get-ChildItem -Directory #List only directories
Get-ChildItem -File #List only files
发布于 2012-09-06 02:01:35
一种更干净的方法:
Get-ChildItem "<name_of_directory>" | where {$_.Attributes -match'Directory'}
我想知道PowerShell 3.0是否有一个只返回目录的开关;这似乎是一个合乎逻辑的事情。
发布于 2012-09-05 15:34:05
使用:
dir -r | where { $_ -is [System.IO.DirectoryInfo] }
https://stackoverflow.com/questions/3085295
复制相似问题