显示目录的文件和子目录的列表。Displays a list of a directory's files and subdirectories. 如果在没有参数的情况下使用,则此命令将显示磁盘的卷标和序列号,后跟磁盘上的目录和文件的列表 (包含它们的名称和上次修改的日期和时间) 。If used without parameters, this command displays the disk's volume label and serial number, followed by a list of directories and files on the disk (including their names and the date and time each was last modified). 对于文件,此命令将显示名称扩展名和大小(以字节为单位)。For files, this command displays the name extension and the size in bytes. 此命令还显示列出的文件和目录的总数、其累计大小和可用空间 (以字节为单位) 磁盘上剩余。This command also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk.

Dir命令也可以使用不同的参数从 Windows 恢复控制台运行。The dir command can also run from the Windows Recovery Console, using different parameters. 有关详细信息,请参阅 Windows 恢复环境 (WinRE) For more information, see Windows Recovery Environment (WinRE).


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


参数Parameter 说明Description
[<drive>:][<path>] 指定要查看其列表的驱动器和目录。Specifies the drive and directory for which you want to see a listing.
[<filename>] 指定要查看其列表的特定文件或文件组。Specifies a particular file or group of files for which you want to see a listing.
/p/p 一次显示列表的一个屏幕。Displays one screen of the listing at a time. 若要查看下一个屏幕,请按任意键。To see the next screen, press any key.
/q/q 显示文件所有权信息。Displays file ownership information.
/W/w 以宽格式显示列表,每行最多有五个文件名或目录名称。Displays the listing in wide format, with as many as five file names or directory names on each line.
/d/d 以与 /w相同的格式显示列表,但文件按列进行排序。Displays the listing in the same format as /w, but the files are sorted by column.
/a [[:] <attributes> ]/a[[:]<attributes>] 仅显示具有指定属性的这些目录和文件的名称。Displays only the names of those directories and files with your specified attributes. 如果不使用此参数,则该命令将显示除隐藏文件和系统文件之外的所有文件的名称。If you don't use this parameter, the command displays the names of all files except hidden and system files. 如果在不指定任何 属性的情况下使用此参数,则该命令将显示所有文件的名称,包括隐藏文件和系统文件。If you use this parameter without specifying any attributes, the command displays the names of all files, including hidden and system files. 可能的 属性 值的列表如下:The list of possible attributes values are:
  • d -目录d - Directories
  • h -隐藏文件h - Hidden files
  • s 系统文件s - System files
  • l -重新分析点l - Reparse points
  • r -只读文件r - Read-only files
  • a -可用于存档的文件a - Files ready for archiving
  • i -非内容索引文件i - Not content indexed files
可以使用这些值的任意组合,但不要使用空格分隔值。You can use any combination of these values, but don't separate your values using spaces. (可选)可以使用冒号 (: ) 分隔符,或者可以使用连字符 ( ) 作为前缀来表示 "not"。Optionally you can use a colon (:) separator, or you can use a hyphen (-) as a prefix to mean, "not". 例如,使用 -s 属性不会显示系统文件。For example, using the -s attribute won't show the system files.
/o [[:] <sortorder> ]/o[[:]<sortorder>] 根据 sortorder排序输出,可以是以下值的任意组合:Sorts the output according to sortorder, which can be any combination of the following values:
  • n -按名称的字母顺序n - Alphabetically by name
  • e -按扩展字母顺序e - Alphabetically by extension
  • g -组目录优先g - Group directories first
  • s -按大小,最小优先s - By size, smallest first
  • d按日期/时间排序,首先是最早的d - By date/time, oldest first
  • 使用 - 前缀反转排序顺序Use the - prefix to reverse the sort order
按列出顺序处理多个值。Multiple values are processed in the order in which you list them. 不要使用空格分隔多个值,但可以选择使用冒号 (: ) 。Don't separate multiple values with spaces, but you can optionally use a colon (:).

如果未指定 sortorderdir/o 会按字母顺序列出目录,后跟文件,它们也按字母顺序排序。If sortorder isn't specified, dir /o lists the directories alphabetically, followed by the files, which are also sorted alphabetically.

/t [[:] <timefield> ]/t[[:]<timefield>] 指定要显示或用于排序的时间字段。Specifies which time field to display or to use for sorting. 可用的 timefield 值包括:The available timefield values are:
  • c -创建c - Creation
  • a上次访问时间a - Last accessed
  • w -上次写入时间w - Last written
/s/s 列出指定目录和所有子目录中指定文件名的每个匹配项。Lists every occurrence of the specified file name within the specified directory and all subdirectories.
/b/b 显示目录和文件的简略列表,无附加信息。Displays a bare list of directories and files, with no additional information. /B参数会重写 /wThe /b parameter overrides /w.
/l/l 使用小写显示未排序的目录名称和文件名。Displays unsorted directory names and file names, using lowercase.
/n/n 显示一种长列表格式,其中的文件名称位于屏幕最右侧。Displays a long list format with file names on the far right of the screen.
/x/x 显示为非8dot3 文件名生成的短名称。Displays the short names generated for non-8dot3 file names. 显示与 /n的显示相同,但短名称插入到长名称之前。The display is the same as the display for /n, but the short name is inserted before the long name.
/c/c 在文件大小中显示千位分隔符。Displays the thousand separator in file sizes. 此选项为默认行为。This is the default behavior. 使用 /c 隐藏分隔符。Use /c to hide separators.
/4/4 以四位数字格式显示年。Displays years in four-digit format.
/r/r 显示文件的备用数据流。Display alternate data streams of the file.
/?/? 在命令提示符下显示帮助。Displays help at the command prompt.


  • 若要使用多个 文件名 参数,请使用空格、逗号或分号分隔每个文件名。To use multiple filename parameters, separate each file name with a space, comma, or semicolon.

  • 您可以使用通配符 (*) ,来表示文件名的一个或多个字符,并显示文件或子目录的子集。You can use wildcard characters (* or ?), to represent one or more characters of a file name and to display a subset of files or subdirectories.

  • 您可以使用通配符 * 来替换任意字符字符串,例如:You can use the wildcard character, *, to substitute for any string of characters, for example:

    • dir *.txt 列出当前目录中扩展名以 .txt 开头的所有文件,例如 .txt、. txt1、. txt_old。dir *.txt lists all files in the current directory with extensions that begin with .txt, such as .txt, .txt1, .txt_old.

    • dir read *.txt 列出当前目录中以读取和开头为 .txt 开头的所有文件,例如 .txt、. txt1 或. txt_old。dir read *.txt lists all files in the current directory that begin with read and with extensions that begin with .txt, such as .txt, .txt1, or .txt_old.

    • dir read *.* 列出当前目录中所有扩展名以 "读取" 开头的所有文件。dir read *.* lists all files in the current directory that begin with read with any extension.

    星号通配符始终使用短文件名映射,因此可能会收到意外的结果。The asterisk wildcard always uses short file name mapping, so you might get unexpected results. 例如,以下目录包含两个文件 ( # B0 2 和 t97.txt) :For example, the following directory contains two files (t.txt2 and t97.txt):

    C:\test>dir /x
    Volume in drive C has no label.
    Volume Serial Number is B86A-EF32
    Directory of C:\test
    11/30/2004  01:40 PM <DIR>  .
    11/30/2004  01:40 PM <DIR> ..
    11/30/2004  11:05 AM 0 T97B4~1.TXT t.txt2
    11/30/2004  01:16 PM 0 t97.txt

    您可能会希望键入的 dir t97\* 将返回 t97.txt 的文件。You might expect that typing dir t97\* would return the file t97.txt. 但是,键入 dir t97\* 将返回这两个文件,因为星号通配符与 t.txt2 的文件 t97.txt 使用其短名称映射 T97B4 ~1.TXT进行。However, typing dir t97\* returns both files, because the asterisk wildcard matches the file t.txt2 to t97.txt by using its short name map T97B4~1.TXT. 同样,键入 del t97\* 将删除这两个文件。Similarly, typing del t97\* would delete both files.

  • 您可以使用问号 (? ) 来替换名称中的单个字符。You can use the question mark (?) as a substitute for a single character in a name. 例如,键入将 dir read???.txt 列出当前目录中所有扩展名为 .txt 的文件(以 read 开头,后跟最多三个字符)。For example, typing dir read???.txt lists any files in the current directory with the .txt extension that begin with read and are followed by up to three characters. 这包括 Read.txt、Read1.txt、Read12.txt、Read123.txt 和 Readme1.txt,但不包括 Readme12.txt。This includes Read.txt, Read1.txt, Read12.txt, Read123.txt, and Readme1.txt, but not Readme12.txt.

  • 如果对属性中的多个值使用 /a ,则此命令仅显示具有所有指定属性的文件的名称。If you use /a with more than one value in attributes, this command displays the names of only those files with all the specified attributes. 例如,如果通过使用或) 使用带有r-h/a作为属性 (/a:r-h ,则 /ar-h 此命令将只显示未隐藏的只读文件的名称。For example, if you use /a with r and -h as attributes (by using either /a:r-h or /ar-h), this command will only display the names of the read-only files that aren't hidden.

  • 如果指定多个 sortorder 值,则此命令将按第一个条件对文件名进行排序,然后按第二个条件对文件名进行排序,依此类推。If you specify more than one sortorder value, this command sorts the file names by the first criterion, then by the second criterion, and so on. 例如,如果通过使用或) 将 /o 与用于排序 (的 e-s参数一起使用,则 /o:e-s /oe-s 此命令将按扩展名对目录和文件的名称进行排序,首先会将其排在最前面,然后显示最终结果。For example, if you use /o with the e and -s parameters for sortorder (by using either /o:e-s or /oe-s), this command sorts the names of directories and files by extension, with the largest first, and then displays the final result. 按扩展名排序的字母排序会导致不带扩展名的文件名先显示,然后是目录名称,然后是带有扩展名的文件名。The alphabetic sorting by extension causes file names with no extensions to appear first, then directory names, and then file names with extensions.

  • 如果使用重定向符号 (>) 将此命令的输出发送到文件,或者使用管道 (|) 将此命令的输出发送到另一个命令,则必须使用 /a:-d/b 才能仅列出文件名。If you use the redirection symbol (>) to send this command's output to a file, or if you use a pipe (|) to send this command's output to another command, you must use /a:-d and /b to only list the file names. 使用filename/s可以 /b指定此命令在当前目录及其子目录中搜索与filename匹配的所有文件名。You can use filename with /b and /s to specify that this command is to search the current directory and its subdirectories for all file names that match filename. 此命令仅列出驱动器号、目录名称、文件名和文件扩展名 (每行一个路径) ,为找到的每个文件名。This command lists only the drive letter, directory name, file name, and file name extension (one path per line), for each file name it finds. 使用管道将此命令的输出发送到另一个命令之前,应在 Autoexec.bat 文件中设置 TEMP 环境变量。Before you use a pipe to send this command's output to another command, you should set the TEMP environment variable in your Autoexec.nt file.


若要逐个显示所有目录,请按字母顺序排列,并以宽格式显示,并在每个屏幕后暂停,确保根目录为当前目录,然后键入:To display all directories one after the other, in alphabetical order, in wide format, and pausing after each screen, make sure that the root directory is the current directory, and then type:

dir /s/w/o/p

输出会列出根目录、子目录以及根目录中的文件,包括扩展名。The output lists the root directory, the subdirectories, and the files in the root directory, including extensions. 此命令还列出树中每个子目录中的子目录名称和文件名。This command also lists the subdirectory names and the file names in each subdirectory in the tree.

若要更改前面的示例,使 dir 显示文件名称和扩展名,但省略目录名称,请键入:To alter the preceding example so that dir displays the file names and extensions, but omits the directory names, type:

dir /s/w/o/p/a:-d

若要打印目录列表,请键入:To print a directory listing, type:

dir > prn

指定 prn后,目录列表将发送到连接到 LPT1 端口的打印机。When you specify prn, the directory list is sent to the printer that is attached to the LPT1 port. 如果打印机连接到不同的端口,则必须将 prn 替换为正确端口的名称。If your printer is attached to a different port, you must replace prn with the name of the correct port.

还可以通过将prn替换为文件名,将dir命令的输出重定向到文件。You can also redirect output of the dir command to a file by replacing prn with a file name. 还可以键入路径。You can also type a path. 例如,若要将 目录输出定向 到 "记录" 目录中的文件 dir.doc,请键入:For example, to direct dir output to the file dir.doc in the Records directory, type:

dir > \records\dir.doc

如果 dir.doc 不存在,则 dir 会创建它,除非 " 记录 " 目录不存在。If dir.doc does not exist, dir creates it, unless the Records directory does not exist. 在这种情况下,将显示以下消息:In that case, the following message appears:

File creation error

若要在驱动器 C 上的所有目录中显示具有 .txt 扩展名的所有文件名的列表,请键入:To display a list of all the file names with the .txt extension in all directories on drive C, type:

dir c:\*.txt /w/o/s/p

Dir命令以宽格式显示每个目录中匹配文件名的按字母顺序排列的列表,并在每次屏幕填满时暂停,直到你按任意键继续。The dir command displays, in wide format, an alphabetized list of the matching file names in each directory, and it pauses each time the screen fills until you press any key to continue.

其他参考Additional References