A quick post this morning on a useful bit of command line magic that generates a list of everything in a folder on Windows and writes it to a file — this comes in useful for install/upgrade documentation and the like, or even just for project tracking and reporting.
- Open a command prompt window (cmd).
- Switch to the folder you want to print a contents listing for (cd a/b/c).
- Type dir >dirlist.txt and hit Return to run the dir command, which lists the folder contents, then dump the results into a file called dirlist.txt in the same folder.
That’s it — job done!
Notes:
- To create the output file elsewhere, give an absolute/relative path along with the filename.
- To include the contents of sub-folders, modifying the command to:
dir /s >dirlist.txt - To see other options that can be used with dir, view the online help by typing:
dir /?