How do I print a listing of files in a directory?
There are different methods of printing a listing of files. However, the method we will be using in this document is directing or sending the output to a file, which can be printed, instead of outputing directly to a printer. Microsoft Windows has no easy method of printing the output of a directory to a file or printer, so outputing to a file and printing that file is the next best solution.
Windows command line and MS-DOS users
- Get to the MS-DOS prompt or the Windows command line.
- Navigate to the directory containing the content you'd like a list to print. If you're new to the command line, familiarize yourself with the cd command and the dir command.
- Once in the directory you want to print the contents of, type one of the following commands.
dir > print.txt
The above command takes the output of the dir command, and writes it to the file print.txt in the current directory, instead of displaying it on the screen.
dir /b > print.txt
The above command would print only the file names and not the file information of the files in the current directory.
dir /s /b > print.txt
The above command would print only the file names of the files in the current directory and any other files in the subdirectories in the current directory.
- After executing any of the above commands, the print.txt file is created. Open this file in any text editor (e.g., Notepad) and print the file. You can also Notepad from the command prompt by typing notepad print.txt. Once in Notepad you can print the file like any other file.
Tip: If you have another default text editor you can also use the start command and start the file to open the file in the default text editor. For example, type start print.txt to open the file in the default text editor.
- Navigate to the directory you want to print. If you're new to Linux, you need to familiarize yourself with the Linux cd command and the ls command.
- Once in the directory you want to print the contents of, type the following command.
ls > print.txt
The above command will print all of the files in the current directory and any subdirectories to the print.txt file.