I have a directory with the following files:
These files will keep updating every few weeks. For example Program-3.0.79.J1232.exe will automatically be put in this directory in a week or two
Using Power Shell, how would I easily go about getting the path of the latest (NOT WITH last modified) file added. Preferably via alphanumeric sorting
It's fairly simple:
((Gci 'C:\\Myfolder' | sort-object name)[-1]).fullname
The [-1
] index means "last item in the array".
Here's another version that also filters out folders in case they exist in the path:
Get-ChildItem c:\temp | `
Where-Object {-not $_.PSIsContainer} | `
Sort-Object Name | `
Select-Object -Last 1 -ExpandProperty FullName
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.