October 13, 2010

Printing a Directory

Filed under: Main — admin @ 12:01 am

There is no way in any graphical operating system I’ve ever used to print out a list of files in a folder. In the older days, at the command prompt, back when it was called a directory of files and not a folder, the command was simple. But not today!

I’m sure there are plenty of utilities out there that print a directory of files. I’ve not found any that I really like. Whatever.

At the command prompt you can still print out a list of files, but you have to be sneaky to do it.

In the old days, the following command would work:

dir > prn

PRN is the code name for the primary printer device in DOS. By typing dir > prn you redirect the output of the dir command, which lists files, to the printer. That command won’t work in current versions of Windows. (I’m not sure about Windows XP, though.)

Even when dir > prn worked, you also had to send a form feed command to the printer to get the entire page to print. That command was echo ^L > prn, where the ^L was the Ctrl+L key combination, which not only cleared the screen but ejected a piece of paper from a printer. (I don’t know if that command still works or not.)

Anyway, it doesn’t work.

What does work is the following three commands.

First, you open a command prompt to the directory you want to print. Yeah, obviously, that takes a familiarity with DOS and its text-mode commands. I’ll assume you know where you’re going (though it’s possible that I may write a later blog post on how to get there). Once there, you type this command:

dir > printdir

That command takes the output of the dir command, which is a list of files, and sends that output to a text file named printdir.

Second, you need to print the text file printdir. You can’t do that from the command prompt, so you have to cheat and run the Notepad program. That can still be done from the command prompt, by typing this command:

notepad /p printdir

The above command runs the Windows Notepad text editor, loads the file names printdir, and prints the file. Then Notepad closes. Ta-da! You have a printed directory of files.

It’s the /p switch that causes Notepad to print the file and close. It’s true: Many of Windows GUI programs have command line options. Sneaky, that Microsoft.

Finally, you need to remove the printdir text file, which has served its purpose:

del printdir

The del command deletes the file; there is no prompt or warning.

Yes, this is technical. Yes, this is awkward. But as far as I know, it’s the only native way to print a list of files in Windows.

2 Comments

  1. This is immensely useful to me. I was not aware of the /p switch for Notepad. In DOS, you could type a /? switch after a command name to get a list of legitimate switches but this does not work in XP. I imagine there might be dozens of useful switches for many XP programs, but I have no idea where these switches are documented.

    Comment by sean bernard — October 13, 2010 @ 5:51 pm

  2. I don’t know if there is a complete list anywhere. Often times you have to search the web and the Windows Help System to find the switches. I remember Notepad’s options where listed in the Help System at one time.

    Word has a bunch of useful options that I’ve documented in Word For Dummies.

    Comment by admin — October 13, 2010 @ 7:16 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.


Powered by WordPress