我需要列出现有目录而不在其中列出文件:
PS C:\Users\myHomeDIR> cat .\toto.txt
.\.config
C:\DA FI
PS C:\Users\myHomeDIR> cat .\toto.txt | dir | % FullName
C:\Users\myHomeDIR\.config\scoop
dir : Cannot find path 'C:\DA FI' because it does not exist.
At line:1 char:18
+ cat .\toto.txt | dir | % FullName
+ ~~~
+ CategoryInfo : ObjectNotFound: (C:\DA FI:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
PS C:\Users\myHomeDIR>
我希望得到这个输出(就像 LINUX
ls -d
那样):
C:\Users\myHomeDIR\.config
dir : Cannot find path 'C:\DA FI' because it does not exist.
At line:1 char:18
+ cat .\toto.txt | dir | % FullName
+ ~~~
+ CategoryInfo : ObjectNotFound: (C:\DA FI:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
ls -Attributes Directory
或者以更类似于 PowerShell 的方式:
Get-ChildItem -Attributes Directory
Get-Item
而不是 Get-ChildItem
(其内置别名之一是 dir
),因为前者总是报告输入项本身,即使它们是目录:
使用其内置的
gi
别名,以及 gc
而不是 cat
作为 Get-Content
别名:
gc .\toto.txt | gi | % FullName