Recursively list files and sort by date modified
In my research project, I often have to quickly navigate through a large directory of study subjects subdirectories containing various files (e.g. PDFs). Finding the files you’ve recently worked on can be ‘challenging’ when the subject names and directories are randomized strings / integers. The command line interface is often the fastest and easiest way of quickly finding this information.
When I want to quickly find the files I’ve added / modified to the study subjects directory, I use the following:
# Use the following snippet of code in a directory to list files, recursively, and then sort them by date modified. gci -file -recurse | select LastWriteTime, Fullname | sort lastwritetime -Descending
When you are confined to a Windows environment and you do not have access to Windows Subsystem for Linux (WSL) or GitBash, PowerShell may be helpful. The code snippet above, which you may find at my GitHub Gist, goes through a directory, finds all files, and sorts them by most recently modified to least recently modified.
License – Share freely and widely
Unless mentioned otherwise, the code above is free for you to use and licensed with the Unlicense License. If you do use it, please drop by my GitHub, and drop the repository a star. Any suggestions or bugs? Create a new Issue on GitHub.