3

I want to take path of one of two identical file in a folder. I'm using:

Get-ChildItem C:\Folder\SomeSubFolder\AnotherFolder\LastFolder\ -recurse -Filter *Someexefiles.exe

How can I modify this code?

4

The below will give you the name & full path for the shortest name found from the results of your filter.

Get-ChildItem C:\Folder\SomeSubFolder\AnotherFolder\LastFolder\ -recurse -Filter *Someexefiles.exe | Select Name, FullName, @{Name = "NameLength"; Expression = {$_.Name.Length}} | Sort NameLength | Select Name,FullName -First 1

If it is the full path that you need to be the shortest its should just be a case of replacing Expression = {$_.Name.Length} with Expression = {$_.FullName.Length}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.