Use the dir command to list files and folders from Command Prompt in Windows 11 and Windows 10. The examples below show how to list names only, search subfolders and filter the output.
List files and folders
- A simple
dircommand without any other arguments lists files and subfolders in the current folder. Hidden and system items are excluded unless we add/a.dir
- List file and subfolder names only.
dir /b
This prints the names without file sizes, modified times or the summary.
- List the files in the current folder and also the ones in the subfolders recursively.
dir /s
List files by extension or name
The dir command accepts wildcards to match file names. The examples below use * to match a string of characters.
- List files of certain type or based on extension
For example, to find JPEG images in the current folder, we can run the below command.dir *.jpg *.jpeg
To find Excel files with .xls or .xlsx extensions:
dir *.xls *.xlsx
We can specify multiple extensions in the same command. For example, to find .docx, .xlsx and .pptx files:
dir *.docx *.xlsx *.pptx
- List files whose names begin with a specific pattern
List matching items in the current folder and its subfolders whose names begin with ‘Picture-‘:dir /S Picture-*
Windows can also match short file names, so wildcard results may include names you did not expect. Use dir /x to see the short names.
List files in another folder
Pass the folder path to dir. Use quotation marks when it contains spaces:
dir "C:\My Files"
To find PDF files in that folder and its subfolders:
dir "C:\My Files\*.pdf" /s /b /a:-d
Here, /s searches subfolders, /b removes the extra information and /a:-d excludes directories. This combination prints one full file path per line.
List only files or only folders
We can use /a to list only files or only directories. These examples also include hidden and system items that match the filter.
- List only directories
dir /A:D
- List only files
dir /A:-D
Display files based on file attributes
We can filter the dir output using read-only, system, hidden and archive attributes.
- For example, to list read-only files in the current directory, the command is:
dir /A:R
- Similarly to display hidden files
dir /A:H
- To list items where an attribute is not set, put
-before the attribute code. For example, to list items without the archive attribute, use:dir /A:-A
- Exclude Read-only files from the listing.
dir /A:-R
- Exclude hidden files from listing.
dir /A:-H
- Exclude system files from listing
dir /A:-S
Print metadata of files using dir command
- Find out who owns a file
dir /Q
Example:
C:\>dir /Q 1.txt 05/03/2015 01:12 AM 151,906 BUILTIN\Administrators 1.txt
The above result of dir indicates that file 1.txt is owned by Administrators group.
- Get created time of a file
dir /TC
- Find last accessed time of a file
dir /TA
- Find last modified time of a file
dir /TW
Save a file list to a text file
To save file names from another folder, redirect the output to a file:
dir "C:\My Files" /b /a:-d > "%USERPROFILE%\file-list.txt"
This creates file-list.txt in your user profile folder. The > operator overwrites the file if it already exists. Add /s to include subfolders and save full paths.
Thanks for the knowledge shared here. Very helpful for my son.
how i can add the time stamp to /s/b
when the files were accessed
Hi , thank you!
I think this was not yet addressed:
How would i include a specific file extension when i also specify a folder, e.g.
dir /b /s /a-d “C:\Users\peter\many LAZ and LAS files folder\” > “File List.txt”Where would i put the *.LAZ expression, if i only want the LAZ files in this directory to be printed in the output list?
Thx, Peter
Hi , thank you!
I think this was not yet addressed:
How would i include a specific file extension when i also specify a folder, e.g.
dir /b /s /a-d “C:\Users\peter\many LAZ and LAS files folder\” > “File List.txt”
Where would i put the *.LAZ expression, if i only want the LAZ files in this directory to be printed in the output list?
Thx, Peter
Extract Web server content:
Web server admin needs to run this one command for each website to extract its structure:
Windows based web servers: dir /S /B /O *.* >> replace_with_Server_Name_website_name.txt
How to use this command
dir /s no longer works correctly. If the directory doesn’t exist, dir /s now finds other directories near by and displays them, but doesn’t list them.
For instance:
dir /s \Scripts\PyScripts\work
shows:
Volume in drive T is WB10TB
Volume Serial Number is 8C30-2523
Directory of T:\Scripts\PyScripts\Keep_Old_Stuff\Scripts\Perl\Scripts\PerlProgs
10/19/2019 03:57 PM work
0 File(s) 0 bytes
Total Files Listed:
0 File(s) 0 bytes
1 Dir(s) 3,967,826,636,800 bytes free
have a directory with the following files:
proc-0000.txt
proc-0001.txt
proc-0002.txt
proc-0003.txt
if i enter “dir *3.*” i get an unexpected return:
proc-0002.txt
proc-0003.txt
why?
if i had these files:
proc-000.txt
proc-001.txt
proc-002.txt
proc-003.txt
and enter ” dir *3.*” i only get (as expected):
proc-003.txt
what is going on with tht dir command?
How can I modify this command to create filelist.txt only if .pdf files are present
dir *.pdf /b /a:-d /o:n > filelist.txt
I am using Windows 10.
I have chosen the 24 hour format HH:mm for time.
And indeed, when use file explorer to examine the contents of a folder, the times
of the files appear in this format.
But when I use the command prompt cmd
and then give the command dir
the times appear in the 12 hour format hh:mm followed by AM or PM.
What can I do so that when I give the dir command the times of the files
will be in the 24 hour format HH:mm
?
Thanks for your help.
I want to take the path from dir filename /s /p and use it to start the program from that path. Is it possible? And if yes could you tell me how.
What if I want to list the filenames from another folder?
When I type dir /e:-d /b , I get an error message that it cannot find e:
Same with dir e: /b and dir /e: /b .
Dir doesn’t seem to work with other folder designations.
Hi,
Thanks for the article
Is there any way to get a list of created date : modified date and access date in one output?
Get created time of a file
dir /TC
Find last accessed time of a file
dir /TA
Find last modified time of a file
dir /TW
Hello,
how can I create a text file list of the contents of a folder and hide the file extensions?
I already have my list of filenames in a file using “dir /b > Songs.xls”, but after every filename in the Songs.xls I still see the extention “.mp3” and I would like this to be removed from the filename.
THX in advance,
Dirkio
How do you list additional attributes to include not only the file name but also the date, type, and size of the file? Thank you.
Special danish characters
I routinely use
dir /o /w > files.txt
to create a text file containing the file names in a folder. I can easily edit that file for use as a table of content for the audio newspaper hosted on our site. The file names are so long, that dir lists them in one column, which is perfect.
BUT: The files have danish special letters æ (html: æ) – ø (ø) – å (å) and their uppercase counterparts, Æ, Ø, Å. These come out wrong with the dir command, and have to be edited manually.
Q: Is there a way to make the dir command output these letters correctly? (Windows 7 Pro, Danish version, computer is NOT connected to the internet…)
/Mads Hansen
you must launch/start/load the CMD tool like “cmd /U” then use again what you were trying
I would like to get the last modified time stamp of the latest file in the directory like just the date and time field values alone into different variables. Something similar to using awk, cut commands in Unix.
Is it possible to get the file icon with dir cmd?
I would like to list files and extract icon to show them in my application.
Is it possible to get dir to print paths with spaces in a directory name?
Answered the question… Now the real problem: Have a command that gives “failed to load external entity” for a file inside a directory with a space. Here’s the command:
for /F %i in (‘dir /s /b D:\YourDirectory\filepath\Folio.xml’) do (C:\progra~1\xmlstarlet\xml.exe ed –inplace -d “//overlay[data/webViewUrl[contains(text(),’shopthis.mastercard’)]]” %i)
Your help is appreciated!
I want to list all the empty subdirectories in a folder and then delete them. How do I do that using dir command
How to get absolute path using command prompt ?
dir /s /bwould print absolute path.