Take smaller file path

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?

1 Answer

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like