Puki
Puki

Reputation: 157

List all folders and subfolders in cmd, but not the files

New to using cmd, just wanted to know is there a way to list all folders their subfolders, if any, but not the files.

e.g.D:\Movies\ dir /s /b gives me list of all files and folders located in Movies, and also its subfolders e.g. D:\Movies\Watched.

I would like to display only folders its subfolders, not their files. Is it possible?

Upvotes: 10

Views: 63269

Answers (1)

Mofi
Mofi

Reputation: 49084

Yes, this is possible as it can be read on running in a command prompt window dir /? which outputs the help for command DIR.

dir D:\Movies\* /AD /B /ON /S

This command outputs

  • only directories because of /AD (attribute directory) including those with hidden attribute set,
  • with only the names of the directories because of /B (bare format),
  • with all subdirectories in a directory sorted by name because of /ON (order by name)
  • of specified directory D:\Movies and all subdirectories because of /S and
  • with full path of each directory also because of /S.

A small modification of the command line is needed to ignore directories with hidden attribute set:

dir D:\Movies\* /AD-H /B /ON /S

-H after /AD results in ignoring hidden directories.

See also:

Upvotes: 26

Related Questions