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.
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.
dir -s
instead of the /s
format for flags. –
Inclusive >list.txt
to make it output to a file to be more easily used. So the command would be: dir /s /b /o:gn >list.txt
–
Hypso 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.
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
powershell
, though) powershell.exe "Get-ChildItem -Recurse . | Resolve-Path -Relative"
Courtesy –
Protolithic 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 -s
- Press Enter
dir
only gives information about the files and directories in the current folder, but the OP wants the return to include files in subfolders as well. –
Olshausen 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.
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
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
© 2022 - 2024 — McMap. All rights reserved.
dir /s
does the job. – Airframechcp 1252
before any of the below solutions to get our special characters right in windows.. – Pectase