命令列出文件夹中的所有文件以及 Windows 中的子文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15214486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:19:26  来源:igfitidea点击:

Command to list all files in a folder as well as sub-folders in windows

windowscommand-linecommanddir

提问by user1760178

I tried searching for a command that could list all the file in a directory as well as subfolders using a command prompt command. I have read the help for "dir" command but coudn't find what I was looking for. Please help me what command could get this.

我尝试使用命令提示符命令搜索可以列出目录中所有文件以及子文件夹的命令。我已经阅读了“dir”命令的帮助,但找不到我要找的东西。请帮我什么命令可以得到这个。

回答by

The below post gives the solution for your scenario.

下面的帖子为您的场景提供了解决方案。

dir /s /b /o:gn


/SDisplays files in specified directory and all subdirectories.

/S显示指定目录和所有子目录中的文件。

/BUses bare format (no heading information or summary).

/B使用裸格式(没有标题信息或摘要)。

/OList by files in sorted order.

/O按文件排序。

回答by Somnath Muluk

If you want to list folders and files like graphical directory tree, you should use tree command.

如果你想像图形目录树一样列出文件夹和文件,你应该使用tree 命令

tree /f

There are various options for display format or ordering.

有多种显示格式或排序选项。

Check example output.

检查示例输出。

enter image description here

在此处输入图片说明

Answering late. Hope it help someone.

回复晚了。希望它可以帮助某人。

回答by Laszlo Lugosi

An addition to the answer: when you do not want to list the folders, only the files in the subfolders, use /A-Dswitch like this:

答案的补充:当您不想列出文件夹,只想列出子文件夹中的文件时,请使用/AD开关,如下所示:

dir ..\myfolder /b /s /A-D /o:gn>list.txt

回答by Bruno

An alternative to the above commands that is a little more bulletproof.

上述命令的替代方案更防弹。

It can list all files irrespective of permissions or path length.

无论权限或路径长度如何,它都可以列出所有文件。

robocopy "C:\YourFolderPath" "C:\NULL" /E /L /NJH /NJS /FP /NS /NC /B /XJ

I have a slight issue with the use of C:\NULL which I have written about in my blog

我在我的博客中写过的 C:\NULL 的使用有一个小问题

https://theitronin.com/bulletproofdirectorylisting/

https://theitronin.com/bulletproofdirectorylisting/

But nevertheless it's the most robust command I know.

但无论如何,这是我所知道的最强大的命令。

回答by xameeramir

If you simply need to get the basic snapshot of the files + folders. Follow these baby steps:

如果您只需要获取文件 + 文件夹的基本快照。请遵循以下婴儿步骤:

  • Press Windows+ R
  • Press Enter
  • Type cmd
  • Press Enter
  • Type dir
  • Press Enter
  • Windows+R
  • Enter
  • 类型 cmd
  • Enter
  • 类型 dir
  • Enter