Ask a question »

MS-DOS - List the contents of a directory in a file

May 2016

MS-Dos - List the contents of a directory in a file


It may be convenient to list the content of one or more directories in a file. Do you require a special software for this purpose? Not really!
Using a simple MS-DOS it is possible to list the content of a directory in text file.
  • Open the command prompt and type the following command:
  • dir c:\mydir>myfile.txt
  • You can list the content of another directory in the same text file using the >> operator:
  • dir c:\mydir>myfile.txt

To have the path of each files listed as well as the organization of the sub-directories, use the below command:
  • dir /b/s c:\mydir>myfile.txt


  • dir displays the contents of a directory on the screen.
  • The > operator indicates how to output the results of the command, in our case a text file!
  • To print this information directly, you can redirect the program output (stdout) to a printer, for example:
    • dir > lpt1
  • >> is a special operator which clear the current content of the output device before displaying new data.

For unlimited offline reading, you can download this article for free in PDF format:

See also

In the same category

Original article published by Jeff. Translated by netsa77. - Latest update by jak58
This document entitled « MS-DOS - List the contents of a directory in a file » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.