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

38,734

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:

Share:
38,734
Puki
Author by

Puki

Updated on April 04, 2020

Comments

  • Puki
    Puki about 4 years

    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?

  • Eryk Sun
    Eryk Sun about 6 years
    I prefer to end with the variable-length sequence of directories to be listed, e.g. dir /ad-h-s /b /on /s d:\videos d:\pictures d:\music [...].