1

I want to get a list of the folders in a certain directory.

Here's how I'm trying to do it:

for /d %%a in (*) do dir "c:\Users\cowman\FolderA" /a:d /o:n /b "%%a" >> get_dirs.txt

This gives me a list of all the folders in FolderA. However, it unfortunately lists the folders multiple times. I only want them listed one time. How do I get them listed one time ?

Magoo
  • 77,302
  • 8
  • 62
  • 84
user2380468
  • 95
  • 1
  • 8
  • Check [this](http://stackoverflow.com/questions/16078421/how-do-i-get-a-list-of-folders-and-subfolders-without-the-files), [this](http://stackoverflow.com/questions/3447503/how-to-get-a-list-of-sub-folders-and-their-files-ordered-by-folder-names), [this](http://www.computerhope.com/issues/ch000772.htm), [this](https://www.google.hr/search?q=cmd+list+of+folders&oq=cmd+list+of+folders&aqs=chrome..69i57j0l3j69i60.2962j0j1&client=ubuntu-browser&sourceid=chrome&ie=UTF-8)... – bosnjak Mar 24 '14 at 08:43
  • Thanks to the people who answered. I see that the problem was caused by my appending the results of the command to an existing file, when I needed to create a new file instead. – user2380468 Mar 24 '14 at 09:12

2 Answers2

2
dir "c:\Users\cowman\FolderA" /a:d /o:n /b > get_dirs.txt

Use > to create the file anew; >> to append to any existing file.

or, if you want a listing of the directories within the subdirectories of your target, use

dir "c:\Users\cowman\FolderA" /a:d /o:n /s /b > get_dirs.txt
Magoo
  • 77,302
  • 8
  • 62
  • 84
0

If you do not want recursive listing use:

dir "c:\Users\cowman\FolderA" /b /ad > get_dirs.txt
Nivlek
  • 553
  • 5
  • 6