Question: Why this command is not sorting the filenames in ascending order from 1 to 20 ?
Not working
Working
Answer :
1 2 3 4 5 |
# Answer: Get-ChildItem -Path 'C:\Logs' | Select-Object -Property Name | Sort-Object -Property { ($_.Name -replace '[^\d]', '') -as [int] } # Explanation: It is needed to sort the filenames as integers : -as [int] |