如何利用 Get-ChildItem 结果?
How exploit Get-ChildItem result?
我想列出所有路径以递归地转到以“_S”结尾的文件夹名称。
我这样做了:
Get-ChildItem -Recurse | Where-Object {($_.Attributes -match "Directory") -and ($_.Name.EndsWith("_S") -and ($_.PSIsContainer -eq 1))}
但结果不是数组。我如何利用结果?
我的目标是拥有这样的东西:
- Myfolder\folder1\folder1_S
- Myfolder\folder2_S
使用Select-Object
并获取文件的FullName
。
此外,正如@Paul 对问题的评论所述,($_.Attributes -match "Directory")
和 ($_.PSIsContainer -eq 1)
是多余的,可能需要删除其中一个。
Get-ChildItem -Recurse | Where-Object {($_.Attributes -match "Directory") -and ($_.Name.EndsWith("_S"))} | Select-Object -ExpandProperty FullName
上述内容也可以在 PowerShell 3.0+ 中重构为
Get-ChildItem -Recurse -Directory -Filter *_S | Select-Object -ExpandProperty FullName
这将递归地获取所有以“_S”结尾的目录的路径
我想列出所有路径以递归地转到以“_S”结尾的文件夹名称。 我这样做了:
Get-ChildItem -Recurse | Where-Object {($_.Attributes -match "Directory") -and ($_.Name.EndsWith("_S") -and ($_.PSIsContainer -eq 1))}
但结果不是数组。我如何利用结果? 我的目标是拥有这样的东西:
- Myfolder\folder1\folder1_S
- Myfolder\folder2_S
使用Select-Object
并获取文件的FullName
。
此外,正如@Paul 对问题的评论所述,($_.Attributes -match "Directory")
和 ($_.PSIsContainer -eq 1)
是多余的,可能需要删除其中一个。
Get-ChildItem -Recurse | Where-Object {($_.Attributes -match "Directory") -and ($_.Name.EndsWith("_S"))} | Select-Object -ExpandProperty FullName
上述内容也可以在 PowerShell 3.0+ 中重构为
Get-ChildItem -Recurse -Directory -Filter *_S | Select-Object -ExpandProperty FullName
这将递归地获取所有以“_S”结尾的目录的路径