How to get better directory listings in a Command Prompt

From ArticleWorld


Although cmd.exe (and its ancestor. command.com) are not exactly the most feature-packed shells around, they still do have some of their tricks. You can use these to obtain more helpful listings, or, if you are using a scripting language, for better integration and more capabilities in scripts.

Interesting options

1. Did you know that you can view directory listings from more than one source? You simply pass more locations as arguments. For example:

C:\> dir C:\Games D:\kidgames

2. You can easily obtain the shortened, 8.3 DOS-style filename along with the long file name without counting letters yourself. Simply use the /X switch:

C:\Games\> dir /X

3. If your script needs absolute paths for files, you can get them using the /S and /B switches:

C:\Games\> dir /S /B

4. You can have your files sorted. For example, you can sort your files by size, using the /OS switch:

C:\Games\> dir /OS

Notes

You can find out more switches using the /? (help) switch. This will display a list of all the options supported by the DIR command.

Although this may seem like quite a lot, the fact that cmd.exe is not to powerful remains. If you can, you should consider getting a replacement, like 4DOS. Or, you may want to check a shell ported from a Unix environment, like sh or bash.