RSS

Using Dir

This entry was posted on Jan 05 2009

The directory (Dir) command is one that many users forget about and yet it’s an incredibly simple means of getting predictable and reliable results when looking for a file. The Microsoft search engine
doesn’t encumber the Dir command and the Dir command doesn’t observe any of the restrictions placed on Windows Explorer. Although Dir lacks some of the display features of Windows Explorer,
it’s possible to locate the files you need and then use Windows Explorer if necessary to perform any required cleanup.

Figure 3.11
The Compact utility tells you the compression status of files on
your system.

The default Dir command displays only visible files in the current folder. By adding wildcard search strings and command line switches, however, you can request almost any kind of file using Dir. For example, if you want to locate all executable files on a certain hard drive, open a command prompt in the root directory and type Dir *.EXE /S. The *.EXE portion tells Dir to look for all files with an EXE extension and the /S switch tells Dir to look in all subdirectories as well as the current directory. Here’s a list of common Dir switches.

/A Display entries with a specific attribute. Add a second letter to define the attribute type including A (archive), D (directory), H (hidden), R (read-only), and S (system). The attribute can also include a – (minus sign) to show you don’t want files with a articular attribute. For example, to look for read-only files without the system attribute, you would include both the /AR and /A-S attributes.

/O Sorts the data using a specific criterion including D (date—oldest first), E (extension), G (group directories first), N (name), and S (size—smallest first). You can add a – minus sign to reverse the sort order. For example, if you wanted to see the newest files first, you’d use the /O-D switch.

/P Tells Dir to pause the display after each screen so you can see the results.
/Q Displays the owner of the file, in addition to all of the other information that Dir provides.
/S Displays the current directory and all subdirectories.
/T Controls the source of the time information provided with the file including C (creation), L (last access), and W (written). For example, if you want to display the date the files were created, you’d use the /TC switch.

/W, /D, and /B Controls how Dir displays the filenames. All three options remove any ancillary information and display just the filenames. The /W switch displays the filenames in as many
columns as will fit across the screen with the files sorted in row order. The /D switch creates the same display as the /W switch, but the files are sorted in column order. The /B switch displays just
the filenames in a single row—this format is especially useful when you want to send the output of the Dir command to a file for later analysis.

Saving Command Output
You can save the output of any command line utility to a text file for later processing using redirection. For example, you can save the output of the Dir command to a file for use in another application or as part of a script.

To redirect the output, you using the > and >> output symbols. The > symbol always creates a new file. The >> symbol adds the current output to an existing file when one exists or creates a new file when
one doesn’t.

Saving the results of a command line utility to the file means adding the correct symbol and a filename to the end of the command. For example, when you type Dir *.* /B >> DirOut.TXT and press Enter, the DirOut.TXT file receives the information from the Dir command

Taken From : Microsoft Windows XP Power Optimization

Post a Comment