Ask a question »

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

March 2015

One can manage a list of data through directory creation in MS-DOS. Also, making a list of directory is possible in MS-DOS. It also allows a user to transfer documents. Displaying the contents of the directory is possible through the command "dir". The peculiar thing about MS-DOS is the fact that the screen, when the command is displayed, has a black background. It is possible to print files directly. This can be done by redirecting the program output to the printer. The contents are automatically sent to the current directory along with the print option.

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


It may be convenient to make a list of one or more directories in a file to make a catalogue of files.

Under MS-DOS (or Windows by opening a window of MS-DOS), it is possible to send the output of a command to a file through redirection>:

dir c:\mydir>myfile.txt

If you want to list several directories, you just run the first command above and use it for all directories following the redirection>>, which operates to concatenate the output to the following file:
  • dir c:\mydir>myfile.txt

The previous method gives a list of files in one directory with all the details, but the disadvantage of adding two lines of presentation of the directory at the beginning of the result and two lines accumulating the total size of files and their number the end.

Another command gives a list of files with a path and guide to automatic sub-directories:
  • dir /b/s c:\mydir>myfile.txt


You'll notice that dir displays the contents of a directory on the screen. The sign > means: "what is left of the sign will be displayed / recorded in what is right of the sign."

You will not see anything on the screen, because that sign means the "show" in a text file rather than on the screen. You can do this with any DOS command (for example, mem> myfile.txt will save information on your memory to the file myfile.txt). To print directly, you can redirect the program output (stdout) to a printer, for example:
  • dir> lpt1

This will send the contents of the current directory to your printer, which will print (if it is plugged into your port lpt1 ...).

>> Is a special operator which deletes what is on 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

Published by netsa77 - Latest update by Celia Gatward
This document entitled « MS-DOS - List the contents of a directory in a file » from Kioskea ( 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.