242

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
StarDotStar
  • 2,865
  • 3
  • 20
  • 15

5 Answers5

419

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

Michael Todd
  • 16,679
  • 4
  • 49
  • 69
  • 9
    +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 – Steven Magana-Zook Jun 05 '13 at 16:49
  • 1
    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! – Walialu Nov 27 '13 at 14:23
  • 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. – kungfooman Jan 22 '14 at 17:21
  • 1
    @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. – Michael Todd Jan 22 '14 at 22:22
  • 2
    Yep, works perfect with Search/Replace "C:/folder" and replace with "". – kungfooman Jan 28 '14 at 17:04
  • 25
    Just to add: `tree /f` gives a pleasing display to the eye :-) – arun Sep 03 '14 at 03:31
  • 1
    @StevenMagana-Zook Add the /p switch to make each key press scroll 1 page. `dir /s /p` – bobroxsox Sep 29 '17 at 03:23
28

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

James Skemp
  • 8,018
  • 9
  • 64
  • 107
Tribrach
  • 281
  • 3
  • 2
27

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

dir /?

For the full list, try:

dir /s /b /a:d
Tilendor
  • 48,165
  • 17
  • 52
  • 58
Fortius
  • 271
  • 3
  • 2
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.

  • Nice! My additional requirement is to count all the lines, which is done with `dir /s /b | find /v /c ""`. – domih Sep 01 '17 at 11:28
4

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

> dir . /s /b sortorder:N