我如何得到一个文件夹和子文件夹的列表没有文件?

我试图打印一个目录的 文件夹子文件夹的列表到一个文件。

当我运行 dir /s/b/o:n > f.txt时,我也会得到一个文件列表。我只需要文件夹和子文件夹。

有人知道这是否可以通过命令行界面实现?

403399 次浏览
 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

just set type of desired file attribute, in your case /A:D (directory)

dir /s/b/o:n/A:D > f.txt

Try this:

dir /s /b /o:n /ad > f.txt

dir /ad /b /s will give the required answer.

I used dir /s /b /o:n /a:d, and it worked perfectly, just make sure you let the file finish writing, or you'll have an incomplete list.

I am using this from PowerShell:

dir -directory -name -recurse > list_my_folders.txt

I don't have enough reputation to comment on any answer. In one of the comments, someone has asked how to ignore the hidden folders in the list. Below is how you can do this.

dir /b /AD-H