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 below commands.
dir > print.txt
The above command takes a list of all the files and all of the information about the files, including size, modified date, etc., and sends that output to the print.txt file in the current directory.
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 sub-directories within 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 print from the command prompt by typing notepad print.txt.
- 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 below command.
ls > print.txt
The above command will print all of the files in the current directory and any sub-directories to the print.txt file.