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.
This question is related to
windows
command-line
command
dir
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.
Following commands we can use for Linux or Mac. For Windows we can use below on git bash.
List all files, first level folders, and their contents
ls * -r
List all first-level subdirectories and files
file */*
Save file list to text
file */* *>> ../files.txt
file */* -r *>> ../files-recursive.txt
Get everything
find . -type f
Save everything to file
find . -type f > ../files-all.txt
If you simply need to get the basic snapshot of the files + folders. Follow these baby steps:
cmd
dir -s
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.
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
Source: Stackoverflow.com