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

February 2017


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


Intro

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

Explanation

  • 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.

Related


Published by netsa77. Latest update on March 17, 2015 at 10:06 AM by jak58.
This document, titled "MS-DOS - List the contents of a directory in a file," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).