I'm looking to grab a list of the directories into a text document using a .bat file or the command line.

The problem I'm facing is that I have roughly twelve hard drives with a few folders in it, then inside those directories are around 163 more folders and I have to catalog them all. Doing this by hand would be a huge task and I'm looking to simplify it.

If you need any more information please just ask and I will provide it.

  • do you simply want to list the directories, or all the files in the directories? – Peter Wright Apr 4 '13 at 18:11
  • 3
    "dir/s" lists everything in every directory. "dir/AD" lists directories only. "tree" lists subdirectories. – FoggyDay Apr 4 '13 at 18:14
  • Just the directories, as the folders contain video files and assets, I just need to know the 'project'(folder) name – azrael Apr 4 '13 at 18:14

You can try different params like /s. How you will do in multiple drives is another matter. You'd end up writing a .bat file which loops through different drives and run the command below. Or simply run this from every drive and collate the results.

dir /s > fileNames.txt

The above will create a fileNames.txt with all dir names.


  • 1
    +1. In Win Server 2008 R2 64-Bit, this command listed all files not just folders. – s15199d Jul 18 '13 at 17:52


tree C: > out.txt
tree D: >> out.txt
tree Z: >> out.txt

You will need to do some editing, but the escape characters do help with the heirarchy.

  • The tree structure does not encode properly in a text file for me. Do I need a particular encoding? – i did not pay the royalties Aug 3 '17 at 7:10
  • 1
    It probably just does not render as you expect based upon your text editor. If you are using Notepad++ from the main menu select Encoding > Character sets > Western European > OEM-850. Any OEM should work regardless of your language base. – zam664 Aug 3 '17 at 12:38

You want the dir command with the flag /s.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.