DIR
to generate a file list for further processing, keep in mind that the output of the DIR
command varies with the operating system, its version and the language and country settings!@ECHO OFF
DIR /B "%*"*
DIR /A/OGN
SET DIRCMD=/A/OGN
DIR
in batch files, prevent weird DIRCMD
settings from ruining your batch file. DIRCMD=/P
for example, might stop your batch file where you least expected it.DIR
does exactly what you intend it to do, never assume any defaults!DIR /-A /-B /-O /-P /-S /-W
/-P
and /-W
don't do what they were supposed to do./P
or /W
./P/-P
and /W/-W
(tip provided by Walter Zackery).DIRCMD
(tip provided by "Explorer"):SETLOCAL
SET DIRCMD=
DIR whatever
ENDLOCAL
DIR
parameters:ATTRIB +H C:\FOLDER
DIR C:\ /A/S
DIR C:\ /A
will show C:\FOLDER itself, but not the files, unless you manage to change to that directoryDIR /Z
will display short file names only./S
, however, subdirectory names will be displayed with their long names. (tip from Georg Pohl and Tom Lavedas)DIR /V
will display file attributes too.26-06-99 12:25 4.409 0 a--- batchfiles.html
27-06-99 20:38 5.789 0 a--- batexamples.html
27-06-99 23:00 5.548 0 a--- batlinks.html
22-06-99 22:20 2.897 0 a--- batutils.html
CONFIG SYS 494 8.192 11-10-99 21:39 11-11-99 A CONFIG.SYS
IO SYS 222.390 229.376 19-02-99 0:36 08-11-99 RHS IO.SYS
MSDOS SYS 1.676 8.192 30-05-99 0:01 11-11-99 RHS MSDOS.SYS
/TA
swich will display 00:00 for the time of every file and directory.@ECHO OFF
IF "%1"=="/?" GOTO Syntax
VER | FIND "Windows NT" > NUL
IF ERRORLEVEL 1 GOTO Syntax
SET FAT=
FOR /F "TOKENS=2,3* DELIMS= " %%A IN ('DIR/A/TA/P/-P/W/-W %~d1 ˆ| FIND ":" ˆ| FIND "-"') DO IF NOT "%%A"=="00:00" SET FAT=non-
ECHO.
ECHO Drive %~d1 has %FAT%FAT file system
GOTO:EOF
:Syntax
ECHO.
ECHO IsFAT, Version 1.00 for NT
ECHO Written by Rob van der Woude
ECHO.
ECHO Usage: ISFAT [ drive ]
:End
/P/-P
and /W/-W
switches overrule DIRCMD /P
and /W
settings, assuring the proper output format for DIR
(tip provided by Walter Zackery)DIR
with its /OA
switch./4
switch./Q
switch:C:\>DIR /Q
Volume in drive C is BOOTDISK
Volume Serial Number is B00D-F10B
Directory of C:\
18-11-2001 18:17 580 BUILTIN\Administrators comreads.dbg
18-11-2001 18:17 545 BUILTIN\Administrators comused.dbg
01-01-2002 13:01 <DIR> BUILTIN\Administrators Documents and Settings
26-01-2002 11:06 <DIR> BUILTIN\Administrators Program Files
25-01-2002 21:15 <DIR> BUILTIN\Administrators TEMP
25-01-2002 20:53 <DIR> BUILTIN\Administrators WINNT
2 File(s) 1,125 bytes
4 Dir(s) 3,813,990,400 bytes free
C:\>
DIR
display short (8.3 format) file names in Windows 2000, /X
and /-N
:D:\>DIR /X
Volume in drive D is DATA
Volume Serial Number is DADA-D15C
Directory of D:\
19-08-2005 22:42 2 FILE~1.WIT File.with very long extension
30-03-2005 20:15 43 TEMP.TMP
30-03-2005 20:15 210 test.bat
19-08-2005 22:27 2 VERYLO~1.TXT Very long file name.txt
4 File(s) 257 bytes
2 Dir(s) 27.170.144.256 bytes free
D:\>
D:\>DIR /-N
Volume in drive D is DATA
Volume Serial Number is DADA-D15C
Directory of D:\
FILE~1 WIT 2 19-08-2005 22:42
TEMP TMP 43 30-03-2005 20:15
test bat 210 30-03-2005 20:15
VERYLO~1 TXT 2 19-08-2005 22:27
4 File(s) 257 bytes
2 Dir(s) 27.170.144.256 bytes free
D:\>
DIR /-N
the short file names and extensions are displayed in separate fixed width columns, separated by one or more spaces, whereas DIR /X
displays the short file names and extensions linked by a single dot.%%~sA
to display fully qualified short file names.D:\Program Files\Perl\.cpan\build\Getopt-Mixed-1.008\lib\Getopt>DIR
Volume in drive D is DATA
Volume Serial Number is DADA-D15C
Directory of D:\Program Files\Perl\.cpan\build\Getopt-Mixed-1.008\lib\Getopt
13-12-2003 21:13 <DIR> .
13-12-2003 21:13 <DIR> ..
09-02-1996 02:05 25.646 Mixed.pm
1 File(s) 25.646 bytes
2 Dir(s) 27.170.144.256 bytes free
D:\Program Files\Perl\.cpan\build\Getopt-Mixed-1.008\lib\Getopt>FOR %A IN (*.*) DO @ECHO.%~sA
D:\PROGRA~1\Perl\CPAN~1\build\GETOPT~1.008\lib\Getopt\Mixed.pmd.pm
D:\Program Files\Perl\.cpan\build\Getopt-Mixed-1.008\lib\Getopt>
page last modified: 2016-09-19; loaded in 0.0020 seconds