dir - Search for files
The dir command lists the files and folders in a directory. Combined with wildcards and options, it also works as a file search tool.
This article covers the basics of dir, how to search for files, and the most useful options.
Quick Answer
| Goal | Command |
|---|---|
| List the contents | dir |
| Filter by extension | dir *.txt |
| Search including subfolders | dir /s *.txt |
| Show file names only | dir /b |
| Show hidden files | dir /a:h |
| Sort by name, size, or date | dir /o:n /o:s /o:d |
Basics of the dir Command
Run without arguments, it lists the files and folders in the current directory.
It works the same way in a batch file.
@echo off
setlocal
dir
endlocal
exit
To inspect another folder, specify its path.

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超 入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
Searching for Files
Search with Wildcards
Use * (any string) and ? (any single character) to display only matching files.
This lists the text files (.txt) in the current directory.
Include Subfolders (/s)
The /s option searches the current directory and all of its subfolders.
Combined with /b, only the full path of each match is shown, which is handy for finding where a file is located.
Main Options of the dir Command
/a: Filter by Attribute
/a:attribute shows only files and folders with the given attribute. Without it, dir does not show hidden or system files.
| Option | Description |
|---|---|
| /a:d | Folders only |
| /a:-d | Files only (exclude folders) |
| /a:h | Hidden files |
| /a:s | System files |
| /a:r | Read-only files |
/b: Names Only
Omits details such as date and size and shows only file and folder names. This is also useful when passing results to other commands.
/o: Sorting
| Option | Description |
|---|---|
| /o:n | Sort by name (ascending) |
| /o:-n | Sort by name (descending) |
| /o:s | Sort by size (ascending) |
| /o:-s | Sort by size (descending) |
| /o:d | Sort by date modified (ascending) |
| /o:-d | Sort by date modified (descending) |
Summary
dirlists a folder’s contents, and wildcards narrow the results/ssearches subfolders, and combined with/bit returns full paths/a,/band/ocontrol what is shown, how, and in what order