在PowerShell中等效于»dir / s / b * foo * .docx«

时间:2014-12-09 11:18:54

标签: powershell cmd

我正在为cmd.exe

寻找powershell等价物
dir /s /b *foo*.docx

我想为此创建一个别名(或scriptlet?)。

我找到How do I do 'dir /s /b' in PowerShell?但是通过这种方法,我似乎无法传递参数*foo*.docx

2 个答案:

答案 0 :(得分:3)

正如我在上面的评论中所述,您正在寻找:

gci -recurse -filter *foo*.docx | select -expandproperty fullname

gciGet-ChildItem将返回与您指定的过滤器匹配的文件系统对象列表。每个对象都会随附一大堆信息,但由于您只对路径感兴趣,因此您可以通过管道传递fullname属性select,如图所示。 -expandproperty标志将确保结果作为字符串数组而不是对象列表返回。

答案 1 :(得分:0)

 Get-ChildItem -Recurse -Filter *foo*.docx | Select-Object FullName | Sort-Object Length