Printing Directory Listings
Don't you find it annoying that Windows Explorer has no "print" command? Ha! Here's an area where the command-line environment is much more capable.You can easily print a directory listing from the command line.
You can redirect the output of any dir command to a network printer or to your local printer if you've shared it, using commands such as the following:
cd \Users\\bknittel\Documents\My Music
dir >\\localhost\printername
where printername is the share name of your printer.This technique doesn't tell the printer to finish the last page of the listing, however, and you probably have to manually eject the last page.
Tip: You can gain a bit more control over the process by redirecting the listing to a file and then printing it with Notepad or a word processor. However, if you redirect the directory listing into a file in the same directory you're listing, the listing file will appear in the output. You can avoid this by directing the listing file into another directory, as with these commands:
cd \Users\bknittel\Documents\My Music dir /s >..\list notepad ..\list del ..\list
Note that .. represents the directory one level above the directory being listed. After printing the listing with Notepad, you can delete the scratch file.
Getting Lists of Filenames
The default directory listing format lists dates, sizes, times, header information, and a summary.The /b option asks dir to print a list of names only.The output of such a listing can be redirected to a file, where it can be used as input to programs, batch files, or WSH scripts that want, as input, a list of filenames.
When you use /s and /b, the dir command lists the full path for all files it displays. For example, from my Windows directory, dir /b /s *.wav prints a long list of files starting with these:
C:\WINDOWS\Help\Tours\WindowsMediaPlayer\Audio\Wav\wmpaud1.wav C:\WINDOWS\Help\Tours\WindowsMediaPlayer\Audio\Wav\wmpaud2.wav C:\WINDOWS\Help\Tours\WindowsMediaPlayer\Audio\Wav\wmpaud9.wav C:\WINDOWS\Media\chimes.wav C:\WINDOWS\Media\chord.wav C:\WINDOWS\Media\ding.wav C:\WINDOWS\Media\notify.wav
In this tutorial:
- The CMD Command-Line
- CMD Versus COMMAND
- Running CMD
- Opening a Command Prompt Window with Administrator Privileges
- CMD Options
- Disabling Command Extensions
- Command-Line Processing
- Console Program Input and Output
- Using the Console Window
- I/O Redirection and Pipes
- Copy and Paste in Command Prompt Windows
- Command Editing and the History List
- Name Completion
- Enabling Directory Name Completion
- Multiple Commands on One Line
- Grouping Commands with Parentheses
- Arguments, Commas, and Quotes
- Escaping Special Characters
- Configuring the CMD Program
- The Search Path
- Changing the Path
- Predefined and Virtual Environment Variables
- Setting Default Environment Variables
- Built-in Commands
- Extended Commands
- Listing Files with the Dir Command
- Paginating Long Listings
- Printing Directory Listings
- Sorting Listings
- Locating Alternate File Streams
- Setting Variables with the Set Command
- Conditional Processing with the if Command
- Scanning for Files with the for Command
- Using the for Command's Variable
- Processing Directories
- Numerical for Loop
- Getting More Information