Windows 7 / Getting Started

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
[Previous] [Contents] [Next]