Recursive directory listing in DOS
Solution 1
You can use:
dir /s
If you need the list without all the header/footer information try this:
dir /s /b
(For sure this will work for DOS 6 and later; might have worked prior to that, but I can't recall.)
Solution 2
dir /s /b /a:d>output.txt
will port it to a text file
Solution 3
You can get the parameters you are asking for by typing:
dir /?
For the full list, try:
dir /s /b /a:d
Solution 4
You can use various options with FINDSTR to remove the lines do not want, like so:
DIR /S | FINDSTR "\-" | FINDSTR /VI DIR
Normal output contains entries like these:
28-Aug-14 05:14 PM <DIR> .
28-Aug-14 05:14 PM <DIR> ..
You could remove these using the various filtering options offered by FINDSTR. You can also use the excellent unxutils, but it converts the output to UNIX by default, so you no longer get CR+LF; FINDSTR offers the best Windows option.
Solution 5
I like to use the following to get a nicely sorted listing of the current dir:
> dir . /s /b sortorder:N
Related videos on Youtube
StarDotStar
Updated on November 23, 2021Comments
-
StarDotStar over 2 years
How do we achieve a recursive directory listing in DOS?
I'm looking for a command or a script in DOS which can give me the recursive directory listing similar to
ls -R
command in Unix. -
Steven Magana-Zook about 11 years+1 very handy. If your directories contain lots of files, then this command will scroll them by on the screen too quickly to read. I think it is best to pipe the output of this command to a txt file you can read at your own speed. For example (assuming c:\temp directory is created): dir C:\ /s > C:\temp\CDirectoryListing.txt
-
Walialu over 10 yearsYou sir, are seriously awesome! It worked like a charm! I used it at work (where we are forced to have windows machines) with gVIM! Really, really good! You saved me hours of headache!
-
kungfooman over 10 yearsFor some reason it prints the full absolute path with C:\folder in front when using /S and /B, is that preventable? I only want the relative filename.
-
Michael Todd over 10 years@lama12345 Not that I know of. I guess you could pipe the results to a text file and then remove the relevant path via a text editor though.
-
kungfooman over 10 yearsYep, works perfect with Search/Replace "C:/folder" and replace with "".
-
arun almost 10 yearsJust to add:
tree /f
gives a pleasing display to the eye :-) -
domih almost 7 yearsNice! My additional requirement is to count all the lines, which is done with
dir /s /b | find /v /c ""
. -
bobroxsox almost 7 years@StevenMagana-Zook Add the /p switch to make each key press scroll 1 page.
dir /s /p