Dos - Dir

> Procedural Languages > Dos (Win32 Shell Scripting) and Utilities

1 - About

Dir displays a list of files and subdirectories in a directory.

Advertising

3 - Syntax

DIR 
  [drive:][path][filename] 
  [/A[[:]attributes]] 
  [/B] [/C] [/D] [/L] [/N]
  [/O[[:]sortorder]] 
  [/P] [/Q] [/R] [/S] 
  [/T[[:]timefield]] 
  [/W] [/X] [/4]

where

  • the options without extra attributes are:
Options Description
[drive:][path][filename] Specifies drive, directory, and/or files to list.
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase
/N New long list format where filenames are on the far right.
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/R Display alternate data streams of the file.
/S Displays files in specified directory and all subdirectories.
/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file names. The format is that of /N with the short name inserted before the long name. If no short name is present, blanks are displayed in its place.
/4 Displays four-digit years

The Options with extra attributes are:

  • /A displays files with specified attributes.
    • D Directories
    • R Read-only files
    • H Hidden files
    • A Files ready for archiving
    • S System files
    • I Not content indexed files
    • - Prefix meaning not
  • /O - List by files in the following sorted order:
    • N By name (alphabetic)
    • S By size (smallest first)
    • E By extension (alphabetic)
    • D By date/time (oldest first)
    • G Group directories first
    • - Prefix to reverse order
  • /T - Controls which time field displayed or used for sorting
    • C Creation
    • A Last Access
    • W Last Written
Advertising

4 - Default Switches

The DIRCMD environment variable is used to hold default options for the DIR command.

You can override the default preset switches by prefixing any switch with - (hyphen) for example: /-W.

set dircmd=/-B /Q /L /R

5 - How to

5.1 - Search cached and not cached file in the sub directory

DIR /S /A:H /A:-H *.EXD
 Volume in drive C has no label.
 Volume Serial Number is AEB0-A348

 Directory of C:\Users\gerard\AppData\Local\Temp\VBE

05/23/2012  01:56 PM           140,068 MSComctlLib.exd
05/22/2012  05:09 PM           138,400 MSComctlLib.exd_bak
05/23/2012  01:56 PM           147,284 MSForms.exd
05/22/2012  05:09 PM           147,284 MSForms.exd_bak
               4 File(s)        573,036 bytes

 Directory of C:\Users\gerard\AppData\Roaming\Microsoft\Forms

05/23/2012  01:56 PM           167,456 MSComctlLib.exd
05/22/2012  05:09 PM           165,788 MSComctlLib.exd_bak
               2 File(s)        333,244 bytes

     Total Files Listed:
               6 File(s)        906,280 bytes
               0 Dir(s)  57,546,534,912 bytes free