【问题标题】:How do I get a list of folders and sub folders without the files?如何获取没有文件的文件夹和子文件夹列表?
【发布时间】:2013-04-11 07:12:35
【问题描述】:

我正在尝试将目录的文件夹和子文件夹的列表打印到文件中.

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

有人知道这可以从命令行界面执行吗?

【问题讨论】:

    标签: cmd directory subdirectory


    【解决方案1】:
     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
    

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

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

    【讨论】:

      【解决方案2】:

      试试这个:

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

      【讨论】:

      • 嗨,上面的这个命令还列出了隐藏文件夹和系统文件夹。我们可以忽略这一点吗(即使 Windows 文件夹选项已显示此类文件夹)
      • 也感谢我!你仍然认为这会在 Windows 10 中得到支持吗?我的意思是 DOS 命令?
      • 不确定为什么要混合使用符号?只需使用dir /s /b /o:n /a:d > f.txt 或dir /s /b /on /ad > f.txt。我个人对开关的属性使用: 方法,因为它更清楚发生了什么。
      • @Lankymart 非常好!从来没有过多关注参数表示法的不同方式。
      【解决方案3】:

      dir /ad /b /s 将给出所需的答案。

      【讨论】:

        【解决方案4】:

        我使用了dir /s /b /o:n /a:d,它工作得很好,只要确保你让文件完成写入,否则你会得到一个不完整的列表。

        【讨论】:

          【解决方案5】:

          我在 PowerShell 中使用它:

          dir -directory -name -recurse > list_my_folders.txt
          

          【讨论】:

            【解决方案6】:

            我没有足够的声誉来评论任何答案。在其中一个 cmets 中,有人询问如何忽略列表中的隐藏文件夹。以下是您可以执行此操作的方法。

            dir /b /AD-H
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2013-11-26
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-01-15
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多