Windows cmd show files in directory

I tried searching for a command that could list all the file in a directory as well as subfolders using a command prompt command.
I have read the help for «dir» command but coudn’t find what I was looking for.
Please help me what command could get this.

Martijn Pieters's user avatar

asked Mar 5, 2013 at 1:55

user1760178's user avatar

3

The below post gives the solution for your scenario.

dir /s /b /o:gn

/S Displays files in specified directory and all subdirectories.

/B Uses bare format (no heading information or summary).

/O List by files in sorted order.

Then in :gn, g sorts by folders and then files, and n puts those files in alphabetical order.

Freerey's user avatar

Freerey

1702 silver badges14 bronze badges

answered Mar 5, 2013 at 2:13

5

If you want to list folders and files like graphical directory tree, you should use tree command.

tree /f

There are various options for display format or ordering.

Check example output.

enter image description here

Answering late. Hope it help someone.

answered Aug 24, 2016 at 13:49

Somnath Muluk's user avatar

Somnath MulukSomnath Muluk

55.2k38 gold badges216 silver badges226 bronze badges

6

An addition to the answer: when you do not want to list the folders, only the files in the subfolders, use /A-D switch like this:

dir ..\myfolder /b /s /A-D /o:gn>list.txt

micstr's user avatar

micstr

5,1008 gold badges48 silver badges76 bronze badges

answered May 15, 2015 at 9:39

Laszlo Lugosi's user avatar

Laszlo LugosiLaszlo Lugosi

3,6891 gold badge21 silver badges17 bronze badges

4

If you simply need to get the basic snapshot of the files + folders. Follow these baby steps:

  • Press Windows + R
  • Press Enter
  • Type cmd
  • Press Enter
  • Type dir -s
  • Press Enter

answered Jun 21, 2017 at 12:52

Zameer Ansari's user avatar

Zameer AnsariZameer Ansari

29.2k24 gold badges140 silver badges221 bronze badges

2

An alternative to the above commands that is a little more bulletproof.

It can list all files irrespective of permissions or path length.

robocopy "C:\YourFolderPath" "C:\NULL" /E /L /NJH /NJS /FP /NS /NC /B /XJ

I have a slight issue with the use of C:\NULL which I have written about in my blog

https://theitronin.com/bulletproofdirectorylisting/

But nevertheless it’s the most robust command I know.

answered Aug 9, 2017 at 12:56

Bruno's user avatar

BrunoBruno

5,7721 gold badge26 silver badges43 bronze badges

The below post gives the solution for your scenario.

**dir /s /b /o:gn**

/S Displays files in specified directories and all subdirectories.

/B Uses bare format (no heading information or summary).

/O List by files in sorted order.

:gn, g sorts by folders and then files, and n puts those files in alphabetical order.

Just for all files except long path, write the following command:

**dir /b /o:gn**

For Tree:
write in your cmd

tree /f

answered Oct 24, 2022 at 13:23

Tabish Zaman's user avatar

Whenever you want to search and make a list of all files on a specific folder, you used the windows explorer interface to do that. But today in this article we will show other easy ways to that. We will list files using the cmd tool. Command-line provides a simple way to list all the files of a certain type– for example, all your PDF files using the “dir” command. This command will be old news to many but it remains one of the most useful for average PC users. At the end of the post, you will have all switches in order t play with them based on your needs,

How to List all the files in a folder using CMD

  1. Searching on windows the “cmd” name an open as administrator
  2. Navigate to your path where you need to list the file by type cd and the path:
cd c:\Test\
  1. Click Enter
  2. Execute the following command
dir

Enter “dir” to list the files and folders contained in the folder.

How to List all the files in a folder and subfolder using CMD

If you want to list the files in all the subfolders as well as the main folder, enter:

dir /s

The lists can be quite long and we will create a file containing the list in order to be very easy. You can rename multiple files at once using CMD.

How to list specific file using wildcards

The dir command can also be used to search for specific files and directories by using wildcards. For example, to list files or directories that begin with the letter “B” you could type:

dir b*

To list only the items starting with the B letter.

How to 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

How to create a text file listing of the files

  1. Open the command line in the folder of interest. Example:
cd c:\Test\
  1. Execute the following command:
    dir > listoffiles.txt
  2. The command will create a list with the files and folders contained in the folder.
  3. If you want to list the files in all the subfolders as well as the main folder, enter the following command
dir /s >listmyfiles.txt

The file “listoffiles.txt” will be created automatically in the working folder.

Give the full pathname to create the file elsewhere. For example:

dir >D:\listmyfiles.txt

Could be used to place the list on an external drive D:

How to create a text file listing only certain types of files

You may want a list of certain types of files such as pdf files. The dir command allows the use of the wildcard symbol *, which adds very useful functionality. Here are some examples.

How to create a list of all the PDF files in a folder and its subfolders:

The command is:

dir /s *.pdf >listpdf.txt

The command will create a list of PDF files only.

A simpler format:

The commands as written will make lists that include information about files such as size and date of creation. A simpler list containing only file names (with full path) can be obtained with the switch “/b”. An example would be:

dir /s/b *.pdf >listpdf.txt

You can also change extension of multiply files using the command line.

How to display only files without folder names

Adding /a-d to the command removes the names of the directories, so all we have are the file names.

dir /a-d /b >..\listmyfiles.txt

How to Display Results in Columns

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

How to Display Results in Lowercase

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

dir /L

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

All Switches Key

Below are all switches where you can use to create a complex list:

Syntax      DIR [pathname(s)] [display_format] [file_attributes] [sorted] [time] [options]

Key

  • [pathname] The drive, folder, and/or files to display, this can include wildcards:
    • *  – Match any characters
    • ?  – Match any ONE character
  • [display_format]
    • /P   Pause after each screen of data.
    • /W   Wide List format, sorted horizontally.
    • /D   Wide List format, sorted by vertical column.
  • [file_attributes] /A[:]attribute
    • /A:D  Folder         /A:-D  NOT Folder
    • /A:R  Read-only      /A:-R  NOT Read-only
    • /A:H  Hidden         /A:-H  NOT Hidden
    • /A:A  Archive        /A:-A  NOT Archive
    • /A:S  System file    /A:-S  NOT System file
    • /A:I  Not content indexed Files  /A:-I  NOT content indexed
    • /A:L  Reparse Point  /A:-L  NOT Reparse Point (symbolic link)
    • /A:X  No scrub file  /A:-X  Scrub file    (Windows 8+)
    • /A:V  Integrity      /A:-V  NOT Integrity (Windows 8+)
    • /A    Show all files

Several attributes can be combined e.g. /A:HD-R

  • [sorted]   Sorted by /O[:]sortorder
    • /O:N   Name                  /O:-N   Name
    • /O:S   file Size             /O:-S   file Size
    • /O:E   file Extension        /O:-E   file Extension
    • /O:D   Date & time           /O:-D   Date & time
    • /O:G   Group folders first   /O:-G   Group folders last

several attributes can be combined e.g. /O:GEN

  • [time] /T:  the time field to display & use for sorting
    • /T:C   Creation
    • /T:A   Last Access
    • /T:W   Last Written (default)
  • [options]
    • /S     include all subfolders.
    • /R     Display alternate data streams.
    • /B     Bare format (no heading, file sizes, or summary).
    • /L     use Lowercase.
    • /Q     Display the owner of the file.
    • /N     long list format where filenames are on the far right.
    • /X     As for
    • /N but with the short filenames included.
    • /C     Include thousand separator in file sizes.
    • /-C    Don’t include a thousand separators in file sizes.
    • /4     Display four-digit years. In most recent builds of Windows, this switch has no effect.

The number of digits shown is determined by the ShortDate format set in the Control Panel.

Conclusion:

This is all about the methods of how to list files in cmd. Not only but also playing with to get a certain result like export them on a text file or listing only certain types of files.

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.

DIR Command - List Files in Windows Command Prompt

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.

  • Home
  • Partition Magic
  • CMD List Files: How to List Files in Command Prompt Windows 10/11

By Ariel | Follow |
Last Updated

What command can be used to list files in a directory? How to list files in Command Prompt Windows 10/11? A great many people are confused about these questions. In this post, MiniTool explains the Command Prompt list files topic in detail and introduces an alternative to CMD list files.

CMD (Command Prompt) is a powerful Windows built-in tool that can be used to do many works such as CMD copy files, CMD list drives, CMD WiFi password, and more. However, a lot of users don’t how to list files in Command Prompt. Here’s a true example from the StackOverflow forum:

I tried searching for a command that could list all the files in a directory as well as subfolders using a command prompt command. I have read the help for the «dir» command but couldn’t find what I was looking for. Please help me with what command could get this.

https://stackoverflow.com/questions/15214486/command-to-list-all-files-in-a-folder-as-well-as-sub-folders-in-windows

Although there are already many discussions and posts about the Command Prompt list files, most of them lack clear steps and screenshots, which makes people difficult to understand the “CMD list files” operation. Thus, we want to write a complete guide to explain it. Let’s keep reading.

What Command Can Be Used to List Files

To list directory CMD smoothly, you need to know what command can be used to list files in a directory Windows first. The answer is to use the DIR command. This command can be used to show all files and subfolders in the current directory. In addition, it displays the file name, size, and last modification date of each file like File Explorer.

The DIR command is available in CMD for almost all Windows systems, including Windows 11/10/8/7/Vista/XP. Here are the most commonly used command lines about the CMD list directory/files:

  • D: List all directories in the current path
  • R: Show read-only files
  • H: Show hidden files
  • A: Archive files
  • S: List system files
  • I: Not content indexed files
  • L: Reparse points
  • -: Add a minus in front of any of the file attribute to let the DIR command not show that kind of file.

How to List Files in Command Prompt Windows 10/11

How to list files in CMD Windows 10/11? The answer depends on what files you want to list. Here we summarize several common examples of the Windows Command Prompt list files.

Step 1. First of all, you need to navigate to the directory in which you want to list files in File Explorer.

Step 2. Click on the address bar and type cmd in the file path and hit Enter, which will open the Command Prompt window.

Tips:

Also, you can locate the directory first in File Explorer, and then press the Win + R keys to open the Run box, type cmd in it, and hit Enter to open the Command Prompt window.

type cmd in the address bar of File Explorer

Step 3. In the pop-up window, you can list file CMD according to your needs. For example:

Example 1. CMD List all directories and folders under the current path.

dir

run dir in the cmd

Example 2. CMD List folders of the current directory only.

dir /ad

run dir ad

Example 3. CMD list files only under the directory.

dir /a-d

cmd list files only

Example 4. CMD list files and folders under a specific directory (e.g. C:Usersdefaultuser1)

cd C:Usersdefaultuser1

dir

CMD list files of a specific directory

Example 5. CMD list all system files under the directory.

dir /s

CMD list system files

Example 6. CMD list all read-only non-achieve files.

dir /a:r-a

CMD list read only files

Example 7. CMD list all files with the file extension .doc.

Tips:

You can replace the doc with other file extensions such as exe, png, xml, etc.

dir *.doc

CMD list files with doc extension

Example 8. CMD list all files with the file extension .doc and .jpg.

dir *.doc *.jpg

CMD list files with doc and jpg extension

Of course, there are many other dir commands to list file CMD on Windows 10/11 and we can’t explain all in this post. If you want to know more information about Windows CMD list files, you can search for corresponding commands online on Google.

Better Alternative to Command Prompt List Files

Although you can list files in a directory CMD, many professional commands might be unfamiliar to you. How to list all files/folders under a directory more easily? MiniTool Partition Wizard is a better alternative to Windows Command Prompt list files.

Its Space Analyzer feature can show all files/folders under a specific path in the file name, size, last change, extension, percentage of drive, etc. In addition, it tells you what files are taking up your disk space and helps you free up disk space.

MiniTool Partition Wizard FreeClick to Download100%Clean & Safe

list files using MiniTool Partition Wizard

About The Author

Ariel

Position: Columnist

Ariel has been working as a highly professional computer-relevant technology editor at MiniTool for many years. She has a strong passion for researching all knowledge related to the computer’s disk, partition, and Windows OS. Up till now, she has finished thousands of articles covering a broad range of topics and helped lots of users fix various problems. She focuses on the fields of disk management, OS backup, and PDF editing and provides her readers with insightful and informative content.

If you need a list of files in a given directory, for example, so you can loop
through them, how can you get a clean list of file names? On a windows based PC,
you can use dos commands. You’ll need to start by accessing the command line.
Below are directions on how to do that in Windows. Note that if you are using
Stata, you can access the command line by starting the command with a “!” in
other words, do get a list of files in the current directory one would type “!
dir”.

First you’ll need to get to the command prompt, you can do this by going to:

Start -> Run -> Type in “cmd”

final1

This will open the command window. Next I will have to move into the correct
directory. On my computer, the default directory is on the C: drive, but the
folder I want to list the files for is on the D: drive, the first thing I will
see is the prompt “C:\>”. The first command below (d:) changes to the D: drive.
The second command moves to the directory d:mydir
which is the directory I want to list the files in. The final line asks for a
listing of the directory, the resulting list of files is shown below.

d:
cd d:\mydir
dir

list_files_dir

Now I know I’m in the right directory. The basic command to list the files in
a directory and place them in a text file is seen below, dir indicates
that I want a directory listing, and the >..myfile.txt indicates that I want to place
that listing in a file called myfile.txt one directory above the directory I am listing. (If you do
not use the “..” to place the file in the directory above the current directory, myfile.txt will
be listed along with your other files, which you probably don’t want.)

dir >..\myfile.txt

If I open myfile.txt in notepad, I see the following:

 Volume in drive D is New Volume
 Volume Serial Number is 822A-8A09

 Directory of D:mydir

11/15/2007  03:03 PM    <DIR>          .
11/15/2007  03:03 PM    <DIR>          ..
11/15/2007  01:38 PM                 0 10oct2006.txt
11/08/2007  04:28 PM               368 11nov2007.do
11/15/2007  01:39 PM                 0 5june2007.txt
03/11/2007  10:39 AM         1,869,429 beameruserguide.pdf
08/10/2007  01:24 PM            22,016 blog - jsm 2007.doc
04/25/2007  03:07 PM           199,887 clarify.pdf
11/15/2007  01:40 PM                 0 houseplants.txt
04/25/2007  11:42 AM           371,225 Mardia 1970 - multivar skew and kurt.pdf
03/27/2007  01:18 PM           319,864 multiple imputation a primer by schafer.pdf
11/15/2007  02:49 PM                 0 output 1.txt
11/15/2007  02:49 PM                 0 output 2.txt
11/15/2007  02:49 PM                 0 output 3.txt
11/15/2007  02:49 PM                 0 output 4.txt
11/08/2007  03:59 PM             8,514 results.dta
11/15/2007  01:31 PM    <DIR>          sub1
11/15/2007  01:31 PM    <DIR>          sub2
11/14/2007  04:27 PM               952 test.txt
05/21/2007  03:23 PM         1,430,743 zelig.pdf
              18 File(s)      4,225,738 bytes
               4 Dir(s)  249,471,307,776 bytes free

This is a listing of the directory, but it’s not really what I want, there is
too much extra information, so I can add options
to the command to get just the names of the files. Adding /b to the command causes the list
to contain just the file and directory names, not the information on the number of files, when they were
created, etc.. Adding /a-d to the command removes the names of the directories, so all we have
are the file names. (There are a number of other options as well, typing help
dir
will list them. Note that I don’t need to delete myfile.txt to rerun the
command, the old content will automatically be replaced with the output
generated by the new command.

dir /a-d /b >..\myfile.txt

now myfile.txt contains:

10oct2006.txt
11nov2007.do
5june2007.txt
beameruserguide.pdf
blog - jsm 2007.doc
clarify.pdf
houseplants.txt
Mardia 1970 - multivar skew and kurt.pdf
multiple imputation a primer by schafer.pdf
output 1.txt
output 2.txt
output 3.txt
output 4.txt
results.dta
test.txt
zelig.pdf

Now suppose I wanted the list to contain only a certain type of file, for example, only text files
with the extension txt. To do this, I can use a wildcard (*) and the file extention to get only files
with the extention .txt . The command below does this.

dir *.txt /a-d /b >..\myfile.txt

myfile.txt contains:

10oct2006.txt
5june2007.txt
houseplants.txt
output 1.txt
output 2.txt
output 3.txt
output 4.txt
test.txt

  • Windows check disk on boot
  • Windows cmd show all files
  • Windows cmd delete all files in folder
  • Windows cmd show all disks
  • Windows cannot verify the digital signature for this file a recent hardware