Inkey
Inkey

Reputation: 2207

How do I get a list of folders and sub folders without the files?

I am trying to print a list of the folders and sub folders of a directory to a file.

When I run dir /s/b/o:n > f.txt, I get a list of the files also. I only need the folders and sub folders.

Anyone know is this possible to do this from command line interface?

Upvotes: 88

Views: 431154

Answers (6)

Shashank Srivastava
Shashank Srivastava

Reputation: 106

I don't have enough reputation to comment on any answer. In one of the comments, someone has asked how to ignore the hidden folders in the list. Below is how you can do this.

dir /b /AD-H

Upvotes: 7

Sany
Sany

Reputation: 121

I am using this from PowerShell:

dir -directory -name -recurse > list_my_folders.txt

Upvotes: 7

sravan
sravan

Reputation: 31

dir /ad /b /s will give the required answer.

Upvotes: 3

user4950040
user4950040

Reputation: 51

I used dir /s /b /o:n /a:d, and it worked perfectly, just make sure you let the file finish writing, or you'll have an incomplete list.

Upvotes: 5

Endoro
Endoro

Reputation: 37589

Try this:

dir /s /b /o:n /ad > f.txt

Upvotes: 166

evilruff
evilruff

Reputation: 4085

 Displays a list of files and subdirectories in a directory.

 DIR [ drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
  [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

  [drive:][path][filename]
          Specifies drive, directory, and/or files to list.

  /A          Displays files with specified attributes.
  attributes   D  Directories                R  Read-only files
           H  Hidden files               A  Files ready for archiving
           S  System files               I  Not content indexed files
           L  Reparse Points             -  Prefix meaning not

just set type of desired file attribute, in your case /A:D (directory)

dir /s/b/o:n/A:D > f.txt

Upvotes: 21

Related Questions