The Dir
command offers a broad range of command line switches that makes
looking for a file faster than you might think. Remembering all of the
command line switches isn't necessarily easy, but you'll use some of
them more often than you use others. In addition to command line
switches, you can use wildcard characters to extend the functionally of
the search. This command uses the following syntax:
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L]
[/N] [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W]
[/X] [/4]
The following list describes each of the command line arguments.
/A[[:]
attributes]Displays
files with the specified attributes. An attribute defines the file
system characteristics of a file. For example, a file with a hidden
attribute isn't visible from the command prompt unless you use the /AH command line switch. You can also exclude a file with a specific attribute from the search by adding the minus (-) sign in front of the attribute. For example, specifying the /-AD switch
would exclude directories from the output. See the sidebar, "Standard
FAT and NTFS File Attributes" for a list of the command line attributes
you can check from the command line.
/B
Removes
the heading and summary information from the output. You can use this
feature to prepare a directory listing for a batch file or a script. It
also comes in handy when you want to prepare a list of files for a
report.
/C
Displays the thousand
separator in file sizes, which is the default for most systems. This
feature makes the file sizes easier to read. Use the /-C command line switch to remove the thousand separator from the file sizes.
/D
Displays the file
output in a wide list format. Generally, this feature allows the display
to hold more filenames at the expense of additional information, such
as the file size. The Dir command sorts the list by column.
/L
Displays the output using lowercase characters. Generally, the Dir
command displays the filenames using uppercase or mixed case
characters. A mixed case character display is standard for the Windows
command window.
/N
Displays
files using the long list format where filenames appear on the far right
of the display. This is the default setting for the Windows command
window.
/O[[:]
sortorder]Lists the directory in a sorted order. Generally, Windows sorts the directory by name. Normally, the Dir command sorts items in ascending order. You can sort in descending order by adding a minus (-) sign to the command line switch. For example, /-AD would sort the directory in descending date order. You can use any of the sort orders for the output.
E
By extension (alphabetic)
D
By date/time (oldest first)
G
Group directories first
N
By name (alphabetic)
S
By size (smallest first)
/P
Pauses the output after each screen of information.
/Q
Displays the file owner information in addition to the standard file output.
/R
Displays the
alternate data streams in a file. Previously, Windows only displayed the
main data stream. Server Core lets you view the alternative data
streams that many developers use to hide data from view.
/S
Displays the
files in the specified directory and all subdirectories. Each
subdirectory has a separate header unless you specify the /B command line switch.
/T[[:]
timefield]Determines which time field appears in the listing. The Dir
command always uses the visible time field for sorting. The default
setting shows the last modified date. Here are the time field values you
can use.
C
Creation
A
Last Access
W
Last Written
/W
Displays the file
output in a wide list format. Generally, this feature allows the display
to hold more filenames at the expense of additional information, such
as the file size. The Dir command sorts the list by row.
/X
Displays the short names generated for non-8.3 filenames (those used for DOS). The Dir command uses the same format as provided by the /N
command line switch with the short name inserted in front of the long
name. The display contains blanks for any long filenames that don't have
an associated short filename.
/4
Displays the years with four digits. This is the default setting for the Windows command line.
Finding Data Files Quickly
It's no secret that
people have trouble finding their data files. You also won't find many
people who will say that Microsoft has done a good job of making it
easier to find data files. Third-party utilities for locating
information on your hard drive abound because Microsoft hasn't lived up
to people's needs or expectations. Unfortunately, these third-party
utilities also come with hidden security problems, making people wary of
using them. In short, it appears that you can choose between not
finding what you need or turning over the security of your system to
someone else. However, I have a third alternative, one that works well
and doesn't compromise security.
At one time, Microsoft did do
a reasonable job of helping you find the data files that you need. The
only problem is that they never updated the utilities that performed
these tasks with a graphical interface, so you must use them at the
command line. For example, judicious use of the Dir
command will help you locate any file that you can name or identify by
its attributes. For example, if you can't find a file based on the name
because you don't remember it, don't worry; the Dir
command can help you locate it based on the date you created it or on
the file size and I guarantee that it works far better than Windows
Explorer.
Of course, sometimes you
don't know anything about a file except that it contains a certain
reference. That's when I use the FindStr utility. You can search any
file with it, not just data files, and locate the strings you want. I've
even used this utility to find executables on my hard drive based on a
prompt I remembered. In short, you already have the tools you need to
find anything on your hard drive.