顯示目錄的檔案和子目錄清單。 如果沒有參數使用,此命令會顯示磁碟的磁碟區卷標和序號,後面接著磁碟上的目錄和檔案清單(包括其名稱和上次修改的日期和時間)。 對於檔案,此命令會顯示擴展名和位元元組大小。 此命令也會顯示列出的檔案和目錄總數、其累計大小,以及磁碟上剩餘的可用空間(以位元組為單位)。
The dir command can also run from the Windows Recovery Console, using different parameters. 如需詳細資訊,請參閱 Windows 復原環境 (WinRE)。
Syntax
dir [<drive>:][<path>][<filename>] [...] [/p] [/q] [/w] [/d] [/a[[:]<attributes>]][/o[[:]<sortorder>]] [/t[[:]<timefield>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4] [/r]
Parameters
Parameter | Description |
---|---|
[<drive>:][<path>] |
指定您想要檢視清單的磁碟驅動器和目錄。 |
[<filename>] |
指定您想要查看清單的特定檔案或檔案群組。 |
/p | 一次顯示清單的一個畫面。 若要查看下一個畫面,請按任何按鍵。 |
/q | 顯示檔案擁有權資訊。 |
/w | 以寬格式顯示清單,每一行的檔名或目錄名稱多達五個。 |
/d | Displays the listing in the same format as /w, but the files are sorted by column. |
/a[[:]<attributes> ] |
只顯示具有指定屬性之目錄和檔案的名稱。 如果您沒有使用此參數,命令會顯示隱藏和系統檔案以外的所有檔案名稱。 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:
|
/o[[:]<sortorder> ] |
Sorts the output according to sortorder, which can be any combination of the following values:
If sortorder isn't specified, dir /o lists the directories alphabetically, followed by the files, which are also sorted alphabetically. |
/t[[:]<timefield> ] |
指定要顯示或用於排序的時間欄位。 The available timefield values are:
|
/s | 列出指定目錄和所有子目錄中每個出現的指定檔名。 |
/b | 顯示目錄和檔案的裸機清單,沒有其他資訊。 The /b parameter overrides /w. |
/l | 使用小寫顯示未排序的目錄名稱和檔名。 |
/n | 在畫面最右邊顯示具有檔名的長清單格式。 |
/x | 顯示非 8dot3 檔名所產生的簡短名稱。 The display is the same as the display for /n, but the short name is inserted before the long name. |
/c | 以檔案大小顯示千位分隔符。 此為預設行為。 Use /-c to hide separators. |
/4 | 以四位數格式顯示年份。 |
/r | 顯示檔案的替代數據流。 |
/? | 在命令提示字元中顯示說明。 |
Remarks
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.
您可以使用通配符 *來取代任何字元字串,例如:
dir *.txt
列出目前目錄中所有擴展名開頭為 .txt的檔案,例如 .txt、.txt1、.txt_old。dir read *.txt
會列出目前目錄中以讀取開頭的所有檔案,以及開頭為 .txt的擴展名,例如 .txt、.txt1 或 .txt_old。dir read *.*
列出目前目錄中以任何擴展名讀取開頭的所有檔案。
星號通配符一律會使用簡短檔名對應,因此您可能會取得非預期的結果。 例如,下列目錄包含兩個檔案 (t.txt2 和 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。 However, typingdir 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\*
會刪除這兩個檔案。您可以使用問號 (?) 作為名稱中單一字元的替代專案。 例如,輸入
dir read???.txt
會列出目前目錄中任何擴展名為讀取且後面最多三個字元的 .txt 檔案。 這包括 Read.txt、Read1.txt、Read12.txt、Read123.txt和 Readme1.txt,但不包括 Readme12.txt。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. 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.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. 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. 依擴展名的字母排序會導致沒有擴展名的檔名先出現,再顯示目錄名稱,再顯示擴展名為的檔名。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. 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. 此命令只會針對找到的每個檔名,列出驅動器號、目錄名稱、檔名和擴展名(每行一個路徑)。 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.
Examples
若要依字母順序顯示所有目錄,以寬格式顯示,並在每個畫面之後暫停,請確定根目錄是目前目錄,然後輸入:
dir /s/w/o/p
輸出會列出根目錄、子目錄和根目錄中的檔案,包括擴展名。 此命令也會列出樹狀結構中每個子目錄中的子目錄名稱和檔名。
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
若要列印目錄清單,請輸入:
dir > prn
When you specify prn, the directory list is sent to the printer that is attached to the LPT1 port. If your printer is attached to a different port, you must replace prn with the name of the correct port.
You can also redirect output of the dir command to a file by replacing prn with a file name. 您也可以輸入路徑。 For example, to direct dir output to the file dir.doc in the Records directory, type:
dir > \records\dir.doc
If dir.doc does not exist, dir creates it, unless the Records directory does not exist. 在此情況下,會出現下列訊息:
File creation error
若要顯示磁碟驅動器 C 上所有目錄中所有擴展名為 .txt 擴展名的所有檔案名清單,請輸入:
dir c:\*.txt /w/o/s/p
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.