René Nyffenegger
René Nyffenegger

Reputation: 40563

What is the equivalent of »dir /s /b *foo*.docx« in powershell

I am looking for the powershell equivalent for cmd.exe's

dir /s /b *foo*.docx

I'd like to create an alias (or scriptlet?) for this.

I have found How do I do 'dir /s /b' in PowerShell? but with this approach I seem unable to pass the argument *foo*.docx.

Upvotes: 0

Views: 1494

Answers (2)

arco444
arco444

Reputation: 22861

As stated in my comment above, you're looking for:

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

gci or Get-ChildItem will return a list of file system objects that match the filter you specified. Each object will have a whole load of information attached with it, but as you're only interested in the path, you can just take the fullname property by piping to select as shown. The -expandproperty flag will ensure the result is returned as a string array rather than a list of objects.

Upvotes: 3

mhatch73
mhatch73

Reputation: 112

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

Upvotes: 0

Related Questions