2012-05-09 71 views
19

我需要列出這些文件的名稱和它保存爲文本文件!如何列出使用DOS命令的文件?

我做什麼,我用下面的DOS命令

x:\xyz> dir *.* > files.txt 

這是什麼一樣的是,它存儲出現在目錄中的xyz的文件的名稱,以及文件的大小,時間和日期!

如何獲得只有文件的名稱?

回答

37

嘗試dir /b,對於裸格式

dir /?會告訴你的,你可以用dir命令做什麼文檔。下面是從我的Windows 7機器的輸出:

C:\>dir /? 
Displays a list of files and subdirectories in a directory. 

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

    [drive:][path][filename] 
       Specifies drive, directory, and/or files to list. 

    /A   Displays files with specified attributes. 
    attributes D Directories    R Read-only files 
       H Hidden files    A Files ready for archiving 
       S System files    I Not content indexed files 
       L Reparse Points    - Prefix meaning not 
    /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. 
    /O   List by files in sorted order. 
    sortorder 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 
    /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. 
    /T   Controls which time field displayed or used for sorting 
    timefield C Creation 
       A Last Access 
       W Last Written 
    /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 

Switches may be preset in the DIRCMD environment variable. Override 
preset switches by prefixing any switch with - (hyphen)--for example, /-W. 
+0

不幸的是,/ B裸露的命令和/按列開關排序的W和/ D裸機不能一起工作。我不知道的方式來抑制聚合,但易於在DOS中獲得列的順序中的數據。 – ggb667

22

如果你只是想獲得文件名和目錄名無關然後使用:

dir /b /a-d > file.txt 
+0

如果您要篩選的具體類型,例如XML:DIR * .XML/B/A-d/S | sort> files1.txt –