在PowerShell中指定文件夹

现在,在Powershell dir只是Get-ChildItem的别名,我怎么才能得到一个只是文件夹的列表?

我在命令提示符下做了dir /ad (属性目录)大约20年。 有没有办法用PowerShell中的参数进行别名化?

我明白了如何使用Get-ChildItem获取目录? 在堆栈溢出,但我不打算inputGet-ChildItem -Recurse | ?{ $_.PSIsContainer } 每次手动 Get-ChildItem -Recurse | ?{ $_.PSIsContainer } 。 理想情况下,我希望dir /ad替代该命令。

把这样的function放在你的configuration文件中:

  function d([string]$switch) { if ($switch -eq "d") { Get-ChildItem -Recurse | ?{ $_.PSIsContainer } } elseif ($switch -eq "f") { Get-ChildItem -Recurse | ?{ !$_.PSIsContainer } } else { Get-ChildItem -Recurse } } 

那就用吧

 dd 

你不能在别名上使用参数,但函数的工作方式是一样的。 你可以使用d -d而不仅仅是dd ,或者你可以使目录成为默认目录,使用d ,可能性是无止境的。 你也可以通过path。

我怎样才能得到只是文件夹的列表?

gci -d只有7个击键input…并且在那里等着你,如果你愿意把你的Powershell升级到v3或者更好。 🙂

gci -d -r如果你想recursion。

编辑:删除选项卡的击键,因为它们是不必要的。