PowerShell tip: quickly list all files with certain file extension, sorted by last editing time
Posted: (EET/GMT+2)
I find myself often wanting to list all files of certain type (file extension) in the order which they have been last modified. For instance, when collecting materials for a developer training session, I often want to find the latest PowerPoint slide decks based on a certain topic.
Things like this are often easiest to implement in the command-line world. With the ol' DOS command "dir", you can pretty easily to get this done with following the command:
dir *.pptx /s /od
This works nicely if all your PowerPoint files (or any other files you are interested in) are in a single folder. But if they are not, then the above command will still sort the files, but only inside each folder, and not across all files found by the command.
Sounds like a job for PowerShell, and indeed, this can be nicely done with the following command:
Get-ChildItem -Recurse -Path . -Filter *.pptx | Sort-Object -Property LastWriteTime -Descending
To run this command, first navigate to the correct root folder you are interested in scanning (such as C:\Trainings), and then run the above command. If you have a large number of files in these folders, the command will take some time to run, especially over a network. But after patiently waiting, you will get the results, neatly sorted globally by last modified date.
Hope this helps!