Generating a List of Directory Contents on Windows

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.

  1. Open a command prompt window (cmd).
  2. Switch to the folder you want to print a contents listing for (cd a/b/c).
  3. 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 /?

 

Author: smurphy

Writer, mother, gardener, geek...