Which windows command displays a list of files and subdirectories in a directory?

The dir command is used to list files and folders in the Windows command prompt (CMD).

dir

The dir command without a path will display a list of files and folders in the current working directory.

Which windows command displays a list of files and subdirectories in a directory?

You can provide a path to see the listing for a different directory:

dir C:\Windows

By default, the dir command does not show hidden files and folders. To include hidden files, run the dir command as follows:

dir /a

You can use the /B switch to show the file names only without heading information or summary.

dir /b C:\Windows

The /s option lists all files in a specified directory and all subdirectories.

dir /s

List Files Using Patterns

The dir command supports wildcard character (*) that you can use to describe a pattern to match.

For example, the following command lists all files that begin with the letter A:

dir a*

Here is another example that lists all files that have a .doc extension:

dir /b *.doc

Displays files with specified attributes

The /A switch is used to list files and folders with specified attributes. For example, the letter H represents the hidden attribute.

dir /a:h

The following table describes each of the values that you can use for Attributes.

D Folders.
H Hidden files and Folders.
S System files.
L Reparse Points.
R Read-only files.
A Files ready for archiving.
I Not content indexed files.
O Offline files.
- Prefix meaning not (See examples).

Examples

List Files and folders in C:\Windows\System32 directory:

dir C:\Windows\System32

Obtain a listing of all files in C:\Windows\System32 that ends with the .txt extension:

dir C:\Windows\System32\*.txt

Search for files with .dll extension in C:\Windows\System32 and all subdirectories:

dir /s C:\Windows\System32\*.dll

Returns the listing for the parent directory of the current working directory:

dir ..

List all files and folders, including hidden files:

dir /a

Show hidden files only:

dir /a:h

List only folders:

dir /a:d

Don't list folders:

dir /a:-d

Show only hidden folders:

dir /a:dh

List read only files:

dir /a:r

Sort the result by name:

dir /o:n

This will sort the result set by size:

dir /o:s

Sort the result set by size (largest first):

dir /o:-s

Sort the result by date:

dir /o:d

Includes the name of the owner for each file:

dir /q

Show creation time:

dir /t:c

Show last access time:

dir /t:a

Show the last written time:

dir /t:w

Run the dir /? command to see a list of all the available command-line options.

Which windows command displays a list of files and subdirectories in a directory?

Run “dir” in Command Prompt to list all of the files and folders in the current directory. Dir alsos take special arguments to sort and select what kinds of files and folders are displayed. For example, “dir /h” will display hidden files.

The DIR command is a powerful Windows Command Prompt function that lists all files and subdirectories contained in a specific directory. The DIR command also offers some switches that unlock some powerful functionality. Let’s take a look.

DIR Command Switches

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. To extend that functionality, you need to use the various switches, or options, associated with the command.

Display Based on File Attributes

You can add “/A” followed by a letter code after the DIR command to display files with a specific attribute. These letter codes include:

  • D: Displays all directories in the current path
  • R: Displays read-only files
  • H: Displays hidden files
  • A: Files that are ready for archiving
  • S: System files
  • I: Not content indexed files
  • L: Reparse points

So, for example, to display just the directories in the current path, you’d type the following command and then hit Enter:

dir /ad

You can combine those codes, too. For example, if you wanted to show only system files that are also hidden, you could use the following command:

dir /ash

You also can add a “-” (minus) in front of any of those letter codes to specify that the DIR command does not show that kind of file. So, for example, if you don’t want to see any directories in the results, you could use this command:

dir /a-d

One more tip: Instead of cramming the main switch and the letter code together the way we did in our examples, you can use a colon to separate the switch from its optional codes. Like this:

dir /a:d

It can make things a little easier to parse, but it’s entirely optional.

Display Stripped Results

Which windows command displays a list of files and subdirectories in a directory?

Using the /b switch with the DIR command strips away all excess information, displaying only the name of the folders and files in the current directory and not attributes like file size and time stamps. Type the following command to make it work:

dir /b

Display Using Thousands Separator

In modern versions of Windows, the Command Prompt shows large numbers separated by commas (so: 25,000 instead of 25000). This wasn’t always the case. In older versions, you had to use the /c switch to show those commas.

Why bother including it here if it’s already the default? Because if for whatever reason you don’t want to show those commas, you can use this switch along with the “-” minus sign:

dir /-c

Display Results in Columns

Which windows command displays a list of files and subdirectories in a directory?

You can use the /D switch to display results in two columns instead of one. When you display results this way, the Command Prompt does not show extra file information (file size and so on)—just the names of the files and directories.

dir /D

Display Results in Lowercase

The /L switch displays all names of files and folders as lowercase.

dir /L

Display Filename Results on the Far Right

Which windows command displays a list of files and subdirectories in a directory?

By default, the Command Prompt displays the names of files to the far right. The /N switch used to be used to achieve this effect. Now, you can use it along with a “-” (minus) to have filenames displayed on the far left instead.

dir /-N

Display Results in Sorted Order

You can use the /O switch followed by a letter code to display directory results sorted in various ways. Those letter codes include:

  • D: Sorts by date/time. Older entries appear first.
  • E: Sorts by file extension in alphabetical order.
  • G: Sorts by listing folders first, then files.
  • N: Sorts by the name of file/folder in alphabetical order.
  • S: Sorts by file size, smallest to largest.

So, for example, you could use the following command to sort results by time and date, with older entries appearing first:

dir /OD

You can also add “-” (minus) before any of the above options to reverse the order. So, for example, if you want to sort files by time and date with newer entries appearing first, you could use this command:

dir /O-D

Display Results One Page at a Time

Which windows command displays a list of files and subdirectories in a directory?

Some directories have hundreds or thousands of files. You can use the /P switch to have the Command Prompt pause the results after it displays each screen. You have to press a key to continue viewing the next page of results.

dir /P

Display Metadata

Which windows command displays a list of files and subdirectories in a directory?

Using the /Q switch on the DIR command displays metadata tied to files and directories, along with ownership details.

dir /Q

Display Alternate Data Streams (ADS)

The /R switch displays any alternate data streams (ADS) that files might contain. ADS are a feature of the NTFS file system that let files contain additional metadata for locating files by author and title.

dir /R

Display All Files and Folders and Everything Inside

You can use the /S switch to recursively show all files and folders inside the current directory. This means all files and folders in every subdirectory, all files and folders in those subdirectories, and so on. Be prepared for a lot of results.

dir /S

Display Results Sorted by Time

Using the /T switch along with a letter code lets you sort results by the different time stamps associated with files and folders. These letter codes include:

  • A: The time the item was last accessed.
  • C: The time the item was created.
  • W: The time the item was last written to. This is the default option used.

So, for example, to sort results by the time items were created, you could use the following command:

dir /TC

Display Results in Wide Format

The /W switch is similar to /D (which shows columns), but instead, it sorts the results in wide format horizontally.

dir /W

Display Short Name Filenames

The /X switch shows a file’s short name when the long name doesn’t comply with 8.3 naming rules.

dir /X

Display Help Pages For DIR

Using the /? switch displays helpful information regarding the DIR command, including a brief description of all the switches we’ve talked about.

Which windows command displays a list of files and subdirectories in a directory?

DIR Command Examples

All right, now you know about the switches and options associated with the DIR command. Let’s take a look at a few real-world examples to gain a better understanding as to how you can start putting them to use.

A simple dir command returns a list of all files and folders in the current directory you’re in.

Which windows command displays a list of files and subdirectories in a directory?

Running the following command shows all system files inside your current path by utilizing the “s” attribute:

dir /a:s

Which windows command displays a list of files and subdirectories in a directory?

But what if you want to view all files of a certain type within all subsequent folders of your current path. That’s easy, just run this extremely fast and useful command:

dir \*.mp3 /s

You can replace the “.mp3” part with whatever file format you’re looking for.

Which windows command displays a list of files and subdirectories in a directory?

The asterisk acts as a wildcard, saying “find anything with .mp3 file format at the end” while the “/s” recursively looks through all folders within your current path.

RELATED: This Command Prompt Trick Searches Way Faster Than Windows Explorer

Now, you may have noticed that returned a LOT of results. Almost too many to be able to read before they scrolled off the screen. This is where we can use the pause switch to give you a chance to read them. To do that, modify the command like this:

dir \*.mp3 /s /p

Which windows command displays a list of files and subdirectories in a directory?

Another trick the Command Prompt offers is called piping. You can use the “>” character to send the results of one command to another place or service. A good example of this is sending all your results to a text file. You can then scroll through them later or import them into other types of documents. To do that, you could use the command:

dir \*.mp3 /s /b > filename.txt

Which windows command displays a list of files and subdirectories in a directory?

RELATED: How to Print or Save a Directory Listing to a File in Windows

We added the /b switch in there to only output the filenames themselves, without any of the other details. The greater than symbol reroutes everything normally displayed in your results directly to the file.


There are many more combinations and uses for the DIR command, but this should be a good starting point to help you understand the basics.

READ NEXT

  • › Are Electric Snow Melting Mats Worth It?
  • › You Can Try Hundreds of ’90s PalmPilot Apps in Your Browser
  • › 10 MacBook Features You Should Be Using
  • › 4 Reasons You Should Still Keep an Optical Drive Around
  • › What Is KaiOS, and Can It Replace iPhone and Android?
  • › This Gaming PC With a Core i5 & RTX 3060 Is $950 Today

What command displays a list of files and subdirectories in a directory?

Use the ls command to display the contents of a directory. The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags.

Which command displays a list of files and directories in Windows?

The command DIR /b will return just a list of filenames, when displaying subfolders with DIR /b /s the command will return a full pathname. To list the full path without including subfolders, use the WHERE command.

What is the command to list all files and subdirectories in a directory quizlet?

The ls command will list directories and files in the current directory by default, however you can specify which path you want to list the directories of. Filenames that start with (.)

Which command will only list the directories in Windows?

Dir is a command found inside the windows command processor (cmd.exe) that is generally used for listing the directories and files within the current directory.