Reputation: 6717
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.
Upvotes: 315
Views: 1967318
Reputation: 111
An addition to the above answers :
To print specific file present in the folders/sub-folders for eg : If you want to list just the csv files then :
dir /b/s/A-D/o:gn *.csv >list.txt
If you want to also include .xlsx files then the code is :
dir /b/s/A-D/o:gn *.csv *.xlsx >list.txt
You can mention more file types in the same way.
P.S Got to know this one from chatgpt :P
Upvotes: 2
Reputation: 292
The below post gives the solution for your scenario.
**dir /s /b /o:gn**
/S Displays files in specified directories and all subdirectories.
/B Uses bare format (no heading information or summary).
/O List by files in sorted order.
:gn, g sorts by folders and then files, and n puts those files in alphabetical order.
Just for all files except long path, write the following command:
**dir /b /o:gn**
For Tree: write in your cmd
tree /f
Upvotes: 5
Reputation:
The below post gives the solution for your scenario.
dir /s /b /o:gn
/S Displays files in specified directory and all subdirectories.
/B Uses bare format (no heading information or summary).
/O List by files in sorted order.
Then in :gn, g sorts by folders and then files, and n puts those files in alphabetical order.
Upvotes: 469
Reputation: 31345
If you simply need to get the basic snapshot of the files + folders. Follow these baby steps:
cmd
dir -s
Upvotes: 9
Reputation: 3829
An addition to the answer: when you do not want to list the folders, only the files in the subfolders, use /A-D switch like this:
dir ..\myfolder /b /s /A-D /o:gn>list.txt
Upvotes: 87
Reputation: 5822
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
https://theitronin.com/bulletproofdirectorylisting/
But nevertheless it's the most robust command I know.
Upvotes: 7
Reputation: 57846
If you want to list folders and files like graphical directory tree, you should use tree command.
tree /f
There are various options for display format or ordering.
Check example output.
Answering late. Hope it help someone.
Upvotes: 201