Paginating Long Listings
If dir prints more names than you can see on the screen at one time, you can scroll back through the listing using the Command Prompt window's scrollbar. You can also ask dir to print only 24 lines at a time-the amount that fits in the default window size-by adding /p to any dir command.When you've caught up with the listing, press Enter to print the next screenful. For example, dir %windir% /p lists the contents of the Windows folder a page at a time.
Searching for Particular Files
You can specify individual filenames or folder names, using wildcards if desired, to limit the listing to specific files and locations.The command dir *.exe lists only files ending in .exe, and dir m*.* lists only files starting with the letter m.
You can add /s to any dir command to make the listing include all subdirectories of the folder in which dir starts its search. For example, dir c:\*.mp3 /s /p locates all MP3 files anywhere on drive C: because it starts in the root directory C:\ and examines all subdirectories. Of course, you can use the Windows Search window to perform this sort of task, but when you already have the Command Prompt window open, it can sometimes be quicker to type a command like this than to poke around with Windows. Of course, whether you use dir or the Search window, you only see files in folders for which you have read permission.
Making Columnar Listings
The options /w and /d print listings of filenames that are arranged in several columns; the exact number of columns is difficult to predict because dir makes the columns wider or narrower depending on the length of the longest filename it finds.The difference between the two options is that /w lists the names by rows, whereas /d sorts them into columns.The /w listing looks like this:
Volume in drive C has no label. Volume Serial Number is DC77-E725 Directory of C:\simh\ibm1130\sw\dmsr2v12 [.] [..] ABOOTPT.asm ABOOTPT.bin ABOOTPT.lst ASYSLDR1.asm ASYSLDR1.bin ASYSLDR1.lst CSYSLDR2.asm CSYSLDR2.bin CSYSLDR2.lst DBOOTCD.asm DBOOTCD.bin DBOOTCD.lst DCILOADR.asm DCILOADR.bin DCILOADR.lst dmsr2v12.zip DSYSLDR1.asm dsysldr1.bin dsysldr1.lst FSYSLDR2.asm FSYSLDR2.bin FSYSLDR2.lst JADUPCO.asm ...
The /w and /d options are particularly useful to get printable listings of your files.
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