如何获取没有文件的文件夹和子文件夹列表?

Ink*_*key 77 directory cmd subdirectory

我试图将目录的文件夹子文件夹列表打印到文件.

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

任何人都知道这可以从命令行界面执行此操作吗?

End*_*oro 141

试试这个:

dir /s /b /o:n /ad > f.txt
Run Code Online (Sandbox Code Playgroud)

  • 不确定为什么要混合符号?,只需使用`dir/s/b/o:n/a:d> f.txt`或`dir/s/b/on/ad> f.txt`.就个人而言,我对交换机的属性使用`:`方法,因为它更清楚发生了什么. (4认同)

evi*_*uff 19

 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
Run Code Online (Sandbox Code Playgroud)

只需设置所需文件属性的类型,在您的情况下/ A:D(目录)

dir/s/b/o:不适用:D> f.txt


San*_*any 6

我在 PowerShell 中使用它:

dir -directory -name -recurse > list_my_folders.txt
Run Code Online (Sandbox Code Playgroud)


小智 5

我使用dir /s /b /o:n /a:d,并且效果很好,只需确保您让文件完成写入,否则列表将不完整。


小智 5

我没有足够的声誉来评论任何答案。在其中一条评论中,有人询问如何忽略列表中的隐藏文件夹。以下是您如何做到这一点。

dir /b /AD-H
Run Code Online (Sandbox Code Playgroud)