Recursive directory listing in DOS
Asked Answered
G

5

244

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.

Greenhaw answered 4/3, 2010 at 4:3 Comment(0)
S
421

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.)

Swindell answered 4/3, 2010 at 4:6 Comment(8)
+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.txtNicobarese
You 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!Allodium
For 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.Fold
@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.Swindell
Yep, works perfect with Search/Replace "C:/folder" and replace with "".Fold
Just to add: tree /f gives a pleasing display to the eye :-)Chalaza
@StevenMagana-Zook Add the /p switch to make each key press scroll 1 page. dir /s /pBlather
If you're using dir > 1.txt, for UTF-8 support, run CHCP 65001>nul before it. (Thanks to this stackoverflow answer)Sheryl
I
28

dir /s /b /a:d>output.txt will port it to a text file

Interchange answered 10/9, 2013 at 19:22 Comment(0)
I
27

You can get the parameters you are asking for by typing:

dir /?

For the full list, try:

dir /s /b /a:d
Interposition answered 12/6, 2012 at 21:51 Comment(0)
U
7

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.

Upward answered 8/10, 2014 at 9:39 Comment(1)
Nice! My additional requirement is to count all the lines, which is done with dir /s /b | find /v /c "".Buckboard
S
4

I like to use the following to get a nicely sorted listing of the current dir:

> dir . /s /b sortorder:N
Septicemia answered 11/12, 2015 at 20:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.