Windows Command Prompt: dir + what option shows only Directories and not files?

All / (switches) in Windows don't have any filter purposes.

I know in Linux it is - (options).

At a Windows command prompt, how can I show only Directories and not Files?

2

2 Answers

This is done by filtering by attributes.dir [somedir] /ad will show all entries with the "directory" attribute. It also shows junction points.

From dir /?:

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

From Microsoft's TechNet - Dir:

If you use /a without specifying Attributes, dir displays the names of all files, including hidden and system files.

The following list describes each of the values that you can use for Attributes. Using a colon (:) is optional. Use any combination of these values, and do not separate the values with spaces.

d Directories

h Hidden files

s System files

l Reparse points

r Read-only files

a Files ready for archiving

i Not content indexed files

- Prefix meaning "not"

6

Using following command you can list only directory (folder) names without any other information.

dir /B /AD 

/A - allows us to specify the attributes that files need to have to be taken into account.

/B - option that means Bare format , i.e. a format that precisely not include header, size, summary, etc.

/D - for Directories

/AD - list only directories.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like