The dir command is a Command Immediate command used to show a listing of the recordsdata and subfolders contained in a folder.

For every file or folder listed, the command will, by default, present the date and time the merchandise was final modified, if the merchandise is a folder (labeled with DIR) or file, the dimensions of the file if relevant, and eventually the identify of the file or folder together with the file extension.

Theresa Chiechi / Lifewire

Exterior of the file and folder record, the dir command additionally shows the present drive letter of the partition, the quantity labelquantity serial quantity, whole variety of recordsdata listed, whole dimension of these recordsdata in bytes, the variety of subfolders listed, and the full bytes remaining free on the drive.

Dir Command Availability

The dir command is obtainable from throughout the Command Immediate in all Home windows working techniques together with Home windows 10Home windows 8Home windows 7Home windows Vista, and Home windows XP.

dir help command in a Windows 10 Command Prompt

Older variations of Home windows embody the dir command as effectively however with a number of fewer choices than we’ve got listed under. The dir command can be a DOS command, accessible in all variations of MS-DOS.

The dir command might be present in offline Command Immediate variations, like those accessible from Superior Startup Choices and System Restoration Choices. The dir command can be included within the Restoration Console in Home windows XP.

The provision of sure dir command switches and different dir command syntax might differ from working system to working system.

Dir Command Syntax

dir [drive:][path][filename] [/a[[:]attributes]] [/b] [/c] [/d] [/l] [/n] [/o[[:]sortorder]] [/p] [/q] [/r] [/s] [/t[[:]timefield]] [/w] [/x] [/4]

See Easy methods to Learn Command Syntax if you happen to’re unsure the way to interpret the syntax of the dir command because it’s written above or proven within the desk under.

Dir Command Choices
Merchandise Clarification
, path, filename
That is the
path, and/or
filename that you simply need to see outcomes for. All three are optionally available for the reason that command might be executed alone. Wildcards are allowed. See the
Dir Command Examples part under if this is not clear.

When executed alone, this swap reveals all kinds of recordsdata and folders, together with these with file attributes that sometimes stop them from displaying up in Command Immediate or in Home windows. Use /a with a number of of the next attributes (colon is optionally available, no areas wanted) to point out solely these kinds of recordsdata within the command end result:

a = archive recordsdata

d = directories

h = hidden recordsdata

i = not content material listed recordsdata

l = reparse factors

r = read-only recordsdata

s = system recordsdata

v = integrity recordsdata

x = no scrub recordsdata

= Use this as a prefix to any of the above attributes to exclude objects with these file attributes from the outcomes.

/b Use this selection to point out the dir outcomes utilizing “bare” format, which removes the standard header and footer info, in addition to all the main points on every merchandise, leaving solely the listing identify or file identify and extension.
/c This swap forces using the hundreds separator when the command is utilized in a approach that reveals file sizes. That is the default habits on most computer systems, so the sensible use is
/-c to disable the hundreds separator in outcomes.
/d Use
/d to restrict the objects displayed to only folders (contained inside brackets) and file names with their extensions. Objects are listed top-to-bottom after which throughout columns. Normal dir command header and footer knowledge stay the identical.
/l Use this selection to point out all folder and file names in lowercase.
/n This swap produces a end result with columns within the
date >
time >
listing >
file dimension >
file or folder identify column construction. Since that is the default habits, the sensible use is
/-n which produces columns within the
file or folder identify >
listing >
file dimension >
date >
time order.

Use this selection to specify a form order for the outcomes. When executed alone, /o lists directories first, adopted by recordsdata, each in alphabetical order. Use this selection with a number of of the next values (colon is optionally available, no areas wanted) to type the dir command end result within the specified method:

d = type by date/time (oldest first)

e = type by extension (alphabetical)

g = group listing first, adopted by recordsdata

n = type by identify (alphabetical)

s = type by dimension (smallest first)

= Use this as a prefix with any of the above values to reverse the order (-d to type by latest first, -s for largest first, and many others.).

/p This feature shows the outcomes one web page at a time, interrupted with a
Press any key to proceed… immediate. Utilizing
/p is similar to utilizing the dir command with the
extra command.
/q Use this swap to show the proprietor of the file or folder within the outcomes. The simplest technique to view or change a file’s possession from inside Home windows is by way of the
Superior button within the
Safety tab when trying on the file’s
/r The
/r choice reveals any alternate knowledge streams (ADS) which can be a part of a file. The information stream itself is listed in a brand new row, below the file, and is at all times suffixed with
$DATA, making them straightforward to identify.
/s This feature reveals all of the recordsdata and folders within the specified listing
plus the entire recordsdata and folders contained inside any subdirectories of that specified listing.

Use this selection with one of many values under (colon is optionally available, no areas wanted) to specify a time area for use when sorting and/or displaying outcomes:

a = final entry

c = created

w = final written

/w Use
/w to point out ends in “wide format” which limits the objects displayed to only folders (contained inside brackets) and file names with their extensions. Objects are listed left-to-right after which down rows. Normal dir command header and footer knowledge stay the identical.
/x This swap reveals the “short name” equal for recordsdata whose lengthy names do not adjust to non-8dot3 guidelines.
/4 The
/4 swap forces using 4-digit years. No less than in newer variations of Home windows, the 4-digit 12 months show is the default habits and
/-4 would not end in a 2-digit 12 months show.
/? Use the
assist swap with the dir command to point out particulars concerning the above choices immediately within the Command Immediate window. Executing
dir /? is similar as utilizing the
assist command to execute
assist dir.

Contemplating the amount of knowledge that the dir command normally returns, saving all of it to a textual content file by way of a redirection operator is normally a sensible concept. See Easy methods to Redirect Command Output to a File for extra on how to do that.

Dir Command Examples

Under are a number of the other ways you need to use the dir command:

Run With out Switches


On this instance, the dir command is used alone, with none drive:, path, filename specs, nor any switches, producing a end result like this:

Quantity in drive C has no label.
Quantity Serial Quantity is F4AC-9851
Listing of C:
09/02/2015 12:41 PM
05/30/2016 06:22 PM 93 HaxLogs.txt
05/07/2016 02:58 AM PerfLogs
05/22/2016 07:55 PM Program Information
05/31/2016 11:30 AM Program Information (x86)
07/30/2015 04:32 PM Temp
05/22/2016 07:55 PM Customers
05/22/2016 08:00 PM Home windows
05/22/2016 09:50 PM Home windows.outdated
1 File(s) 93 bytes

As you may see, the dir command was executed from the root listing of C (i.e., C:>). With out specifying the place precisely to record the folder and file contents from, the command defaults to displaying this info from the place the command was executed.

Record Hidden Objects

dir c:customers /ah

Within the above instance, we’re requesting that the dir command present outcomes from the drive: and path of c:customers, not from the placement we’re operating the command from. We’re additionally specifying, by way of the /a swap with the h attribute, that we might wish to solely see hidden objects, leading to one thing like this:

C:>dir c:customers /ah
Quantity in drive C has no label.
Quantity Serial Quantity is F4AC-9851
Listing of c:customers
05/07/2016 04:04 AM All Customers [C:ProgramData]
05/22/2016 08:01 PM
05/07/2016 04:04 AM Default Person [C:UsersDefault]
05/07/2016 02:50 AM 174 desktop.ini
1 File(s) 174 bytes

The small record of directories and the only file you see within the end result above would not make up the whole lot of the c:customers folder—simply the hidden recordsdata and folders. To see all recordsdata and folders, you’ll execute dir c:customers /a (eradicating the h) as a substitute.

Seek for File In Any Folder

dir c:*.csv /s /b > c:userstimdesktopcsvfiles.txt

On this barely extra complicated, however rather more sensible, instance for the dir command, we’re requesting that our complete laborious drive be looked for CSV recordsdata after which the naked minimal outcomes are outputted to a textual content doc. Let’s take a look at this piece by piece:

  • c:*.csv tells the dir command to have a look at all recordsdata (*) that finish within the CSV (.csv) extension within the root of the c: drive.
  • /s instructs it to go deeper than the foundation of c: and as a substitute, seek for recordsdata like this in each folder, as deep because the folders go.
  • /b removes something however the path and file identify, basically making a readable “list” of those recordsdata.
  • > is a redirection operator, which means “send to” someplace.
  • c:userstimdesktopcsvfiles.txt is the vacation spot for the > redirector, which means that outcomes shall be written to the csvfiles.txt file as a substitute of in Command Immediate, which shall be created on the c:userstimdesktop location (i.e., the Desktop your see once you’re logged in).

While you redirect command output to a file, as we did right here on this dir command instance, Command Immediate would not show something. Nevertheless, the actual output you’ll have seen is as a substitute situated inside that textual content file. This is what our csvfiles.txt regarded like after the dir command had accomplished:

c:UsersAll UsersIntuitQuickenInetmerchant_alias.csv
c:UsersAll UsersIntuitQuickenInetmerchant_common.csv

When you definitely may have skipped the file redirection, and even the “bare format” swap, the outcomes would have been very troublesome to work throughout the Command Immediate window, making it laborious to get to what you had been after.

Associated Instructions

The dir command is commonly used with the del command. After utilizing dir to search out the identify and site of the file(s) in any specific folder(s), del can be utilized to delete recordsdata immediately from the Command Immediate.

Comparable is the rmdir /s command, and older deltree command, used to delete folders and recordsdata. The rmdir command (with out the /s choice) is helpful for deleting empty folders that you simply discover with the dir command.

As talked about above, the dir command can be typically used with a redirection operator.

Leave a Reply

Your email address will not be published.