dir】 显示目录文件和子目录列表【win】


dir [Drive:][Path][FileName] [...] [/p] [/q] [/w] [/d] [/a[[:]Attributes]][/o[[:]SortOrder]] [/t[[:]TimeField]] [/s] [/b] [/l] [/n] [/x] [/c] [/4]

/p 每次以一个屏幕大小显示列表的一部分。要查看下一屏,请按键盘上的任意键

/q 显示文件所有权信息。

/w 以宽格式显示列表,在每一行上显示多个文件名或目录名

/d 与 /w 相似,但是文件按列排序。

/a [[:] Attributes] 只显示那些指定属性的目录名和文件名

/o[[:]SortOrder] 控制 dir 排序和显示目录名和文件名的顺序。

  n 按名称的字母顺序

  e 按扩展名的字母顺序

  d 按日期和时间,最早的优先

  s 按大小,最小的优先

  g 在文件之前分组的目录

  -n 按名称的逆序字母(从 Z 到 A)顺序

  -e 按扩展名的逆序字母(从 .ZZZ 到 .AAA)顺序

  -d 按日期和时间,最晚的优先

  -s 按大小,最大的优先

  -g 在文件之后分组的目录

/t[[:]TimeField] 指定显示或用于排序的时间字段

/s 在指定目录及所有子目录中遍历,如果没给该参数不会在子目录遍历

/b 列出每个目录名或文件名,只有名字

/l 以小写字母形式显示目录名和文件名

/n 在屏幕最右边显示带有文件名的长列表格式。

/x 显示为 NTFS 和 FAT 卷上文件生成的短名称。短名称显示在长名称之左侧

/c 按文件大小显示多个分隔符

/4 显示四位数字的年份格式

Dir】 Display a list of files and subfolders.【win】


Syntax

      DIR [pathname(s)] [display_format] [file_attributes] [sorted] [time] [options]

Key

   [pathname] The drive, folder, and/or files to display,

              this can include wildcards:

                 ? Match any ONE character

   [display_format]

   /P Pause after each screen of data.

   /W Wide List format, sorted horizontally.

   /D Wide List format, sorted by vertical column.

   [file_attributes] /A[:]attribute

   /A:D Folder /A:-D NOT Folder

   /A:R Read-only /A:-R NOT Read-only

   /A:H Hidden /A:-H NOT Hidden

   /A:A Archive /A:-A NOT Archive

   /A:S System file /A:-S NOT System file

   /A:I Not content indexed Files /A:-I NOT content indexed

   /A:L Reparse Point /A:-L NOT Reparse Point (symbolic link)

   /A:X No scrub file /A:-X Scrub file (Windows 8+)

   /A:V Integrity /A:-V NOT Integrity (Windows 8+)

   /A Show all files

   Several attributes can be combined e.g. /A:HD-R

   [sorted] Sorted by /O[:]sortorder

   /O:N Name /O:-N Name

   /O:S file Size /O:-S file Size

   /O:E file Extension /O:-E file Extension

   /O:D Date & time /O:-D Date & time

   /O:G Group folders first /O:-G Group folders last

   several attributes can be combined e.g. /O:GEN

   [time] /T: the time field to display & use for sorting

   /T:C Creation

   /T:A Last Access

   /T:W Last Written (default)

   [options]

   /S include all subfolders.

   /R Display alternate data streams.

   /B Bare format (no heading, file sizes or summary).

   /L use Lowercase.

   /Q Display the owner of the file.

   /N long list format where filenames are on the far right.

   /X As for /N but with the short filenames included.

   /C Include thousand separator in file sizes.

   /-C Don’t include thousand separator in file sizes.

   /4 Display four-digit years.

          In most recent builds of Windows this switch has no effect.

          The number of digits shown is determined by the ShortDate format

          set in the Control Panel.

The switches above can be preset by adding them to an environment variable called DIRCMD.

For example: SET DIRCMD=/O:N /S

Override any preset DIRCMD switches by prefixing the switch with -

For example: DIR *.* /-S

Sorting

    The default Sort Order, if you don’t specify anything with /O, on an NTFS drive will be in sort-of-alphabetical order or on a FAT USB thumb drive, then the order will be based on the order in which files were created and deleted and the lengths of their names.

Upper and Lower Case filenames:

    Filenames longer than 8 characters - will always display the filename with mixed case as entered.

    Filenames shorter than 8 characters - can display the filename in upper or lower case - this can vary from one client to another (registry setting)

    To obtain a bare DIR format (no heading or footer info) but retain all the details, pipe the output of DIR into FIND, this assumes that your date separator is /

    DIR c:\temp*.* | FIND "/"

Listing the full path

    The command DIR /b will return just a list of filenames, when displaying subfolders with DIR /b /s the command will return a full pathname. To list the full path without including subfolders, use the WHERE command.

Errorlevels

    If the file(s) were successfully listed %ERRORLEVEL% = 0

    If the file was not found or bad parameters given %ERRORLEVEL% = 1

All file sizes are shown in bytes.

DIR is an internal command.

Examples

List the contents of c:\demo including ALL files:

DIR /a c:\demo\

List the contents of c:\demo displaying only the filenames:

DIR /b c:\demo\

List only the files (not folders) stored under c:\demo\ recursing into all sub-folders and include any hidden files:

DIR /a:-D /s c:\demo\

List the Full Path of each file in c:\demo WITHOUT using the /S switch: (via Forum)

For %%A in ("c:\demo*") do Echo %%~fA

List the contents of c:\demo and H:\work

notice the trailing backslashes, if either directory does not exist, this will fail and set %Errorlevel% = 1

DIR c:\demo\ h:\work\

List all the Reparse Points (symbolic links) in the current users profile:

DIR %USERPROFILE% /a:i

List the contents of c:\demo, without the header/footer details:

FOR /f "tokens=*" %%G IN ('DIR c:\demo*.* ^| find "/"') DO echo %%G


腾图小抄 SCWY.net v0.03 小抄561条 自2022-01-02访问365336次