Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 525
Puki Avatar asked Feb 27 '18 00:02

Puki


People also ask

How do I get a list of all folders and subfolders?

Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory. WARNING: This can take a while if you have a large directory.

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

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

How do I show only directories in CMD?

You can use the DIR command by itself (just type “dir” at the Command Prompt) to list the files and folders in the current directory.

How do I remove subfolders but keep files in Windows?

Open up a File Explorer window in the folder containing the other folders. In the search box (top right), type NOT kind:folder . You will now see a list of all files in your current folder and all its subfolders. Use Control-A to select all the files.


1 Answers

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:

  • Microsoft's command-line reference
  • SS64.com - A-Z index of the Windows CMD command line
like image 161
Mofi Avatar answered Sep 29 '22 19:09

Mofi