Can't list long filenames in MSDOS?

Dennis Faas's picture

Infopackets Reader Brad B. writes:

" Dear Dennis,

I would like to create a text document which contains a list of my files in a directory. I asked a techie friend of mine how to do it, and he told me to open up an MS DOS Window and use the command: 'dir *.* > list.txt' I did that but my file names aren't showing up in full. Can you help?"

Side note: MS DOS is the predecessor to Windows. The MS DOS prompt provides an optional way to access or modify files through a command line interface. An MS DOS command prompt can be opened by clicking Start -> Programs -> MSDOS, or if you own Windows 2000 or XP, it's Start -> Programs -> Accessories -> Command Prompt.

My response:

Your tech friend was close to getting you on the right track. The command you listed above essentially says "give me a listing of all files in this folder [using the default format] and output the listing to a text file called list.txt".

Before the release of Windows, MS DOS would only list filenames with a maximum of 8 characters, followed by an extension having 3 characters. To overcome this barrier, Microsoft introduced long filename support, permitting filenames up to 255 characters in length.

When a long filename is listed under MS DOS, its format changes. For example, a filename called "mydocument.doc" under Windows may look like "mydocu~1.doc" under MS DOS. This is because (by default) MS DOS can only display 8 characters with a 3 letter extension.

RE: How to list long filenames using MS DOS

To make the 'dir' command print long file names, you need to insert a /n command switch. This tells the 'dir' command to output files using the new long filename format. All together, the command is:

dir /n >list.txt

Side note: You may notice that I omitted the *.* portion of the command. By default, the 'dir' command will infer that you are listing all files in the directory, so the *.* wildcard is not necessary. Wildcards are particularly useful when specifying search criteria (for example: *.doc, which would list only .doc files in the current directory).

If do not want the 'dir' command to output the date stamps for each file, consider using the /b switch. It provides a "bare" listing that outputs only the filenames:

dir /n /b >list.txt

And, if you want to list all the command switches for the 'dir' command, try:

dir /?

Good luck!

Rate this article: 
Average: 5 (1 vote)