How to list all the files in a Windows folder using ms-dos commands?
When it comes to List files in a huge folder with cmd in Windows, it’s highly recommended, even mandatory. Indeed, use scripting to avoid a tremendous manual work and errors. Automation is key here, with very simple bash commands windows system can do all the work.
Indeed, the dir command in MS-DOS is a fundamental tool for managing and organizing files in Windows. It can be used to list all files in a folder, including their attributes such as creation date, type, size, and name. With a few simple options, you can filter and sort the results, making it easier to find the specific files you need. In addition, the dir command can be used to search for files in subdirectories, display files with specific extensions, and show only hidden, read-only, or system files.
Table of Contents
1. List all the files in a folder with MS-DOS
Use the dir command line to display the full list of files inside a specific directory. To display the list of files with some attributes, use the dir command. The default attributes are the following:
- The creation date and time.
- The type, if <DIR> is displayed then it is a directory, if not it is a file.
- The size of the files, in bytes.
- The name of the folder or the file with the extension, like for example file.txt.
The command also lists the total number of files in the folder and the total size. And also the total number of folders and the free disk space available in the current drive in bytes. Please note the dir command without options do not display the hidden files nor the windows system files.
Of course it is also possible to copy Windows files recursively, i.e., copy all files from a folder and its subfolders.
2. Advanced options to list files using the dir command
dir command provides various advanced options that you can use to filter and display specific files, such as:
/A– Display only files with specific attributes (e.g.
/AHto display only hidden files)
/B– Display files in bare format (without additional details like the size or date modified)
/S– Search for files in subdirectories as well
/W– Display files in a wide format (multiple columns, instead of a single column)
*.ext– Display only files with a specific extension (e.g.
dir *.txtto display only .txt files)
Of course you can combine these options together to achieve more specific results. For example,
dir /A /S /W *.txt will search for all .txt files in the current directory and its subdirectories, display them in a wide format, and show only files with specific attributes.
3. Example of scripts using the dir with cmd to list files
One of the key benefits of the dir command is its versatility. By combining options, you can create complex queries to display only the files you need, saving time and reducing manual effort. This is especially useful when dealing with large directories.
Indeed, scrolling through a long list of files is time-consuming and can lead to manipulation errors. The basic examples presented below illustrate how the options are useful.
3.1 Display files with specific attributes
This code will display all files with specific attributes. You can use the following options to filter the results:
/AH– Display only hidden files
/AR– Display only read-only files
/AS– Display only system files
3.2 Search for files inside subdirectories
This code will search for files in the current directory and its subdirectories and display the results.
3.3 Display files with a specific extension with ms-dos
The following ms-dos script display all files with a specific extension, here it is .csv. Replace
*.csv with the extension you want to search for (e.g.
*.txt, or *.jpeg to display only .txt files or JPEG pictures, respectively).
3.4 Combine dir options with ms-dos
This sample command search for all .txt files in the current directory and its subdirectories, display them in a wide format, and show only files with specific attributes.
dir /A /S /W *.txt
Conclusion on listing Windows files using cmd
The dir command in MS-DOS is a powerful tool to manage and list files in a Windows folder with cmd. With a few simple options, you can display a list of all files in a folder, including their creation date, type, size, and name. You can also search for files in subdirectories and display files with specific attributes, such as hidden or read-only files.
By combining multiple options, you can filter the results even further, such as displaying only .txt files in a wide format with specific attributes. Whether you’re looking to automate a tedious manual task or simply get a better overview of the contents of a directory, the dir command is an essential tool for anyone working with Windows command lines.
To go further, this is a tutorial on how to copy files recursively in PowerShell.