dir - ファイルを検索
にメンテナンス済み
dir コマンドは、フォルダ内のファイルやフォルダを一覧表示するコマンドです。ワイルドカードやオプションを組み合わせることで、ファイルの検索にも使えます。
この記事では、dir の基本的な使い方、ファイルの検索方法、よく使うオプションを紹介します。
結論
| やりたいこと | コマンド |
|---|---|
| 一覧を表示する | dir |
| 拡張子で絞り込む | dir *.txt |
| サブフォルダも含めて検索する | dir /s *.txt |
| ファイル名だけ表示する | dir /b |
| 隠しファイルを表示する | dir /a:h |
| 名前順・サイズ順・日付順に並べ替える | dir /o:n /o:s /o:d |
dir コマンドの基本
引数なしで実行すると、カレントディレクトリ内のファイルとフォルダが一覧表示されます。
- □ ×
コマンド プロンプト
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
C:\users\user>dir
バッチファイルでも同様に使えます。
@echo off
setlocal
dir
endlocal
exit
別のフォルダを調べる場合は、パスを指定します。
- □ ×
コマンド プロンプト
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
C:\users\user>dir C:\Users\user\Documents
おすすめ書籍※ 広告を含む場合があります

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
ファイルを検索する
ワイルドカードで検索
*(任意の文字列)や ?(任意の 1 文字)を使うと、条件に合うファイルだけを表示できます。
- □ ×
コマンド プロンプト
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
C:\users\user>dir *.txt
2023/04/29 14:11 7 test2.txt
2023/04/29 14:11 7 text.txt
2 個のファイル 14 バイト
0 個のディレクトリ 266,096,242,688 バイトの空き領域
C:\users\user>
カレントディレクトリ内のテキストファイル(.txt)が一覧表示されます。
サブフォルダも含めて検索(/s)
/s オプションを付けると、カレントディレクトリとすべてのサブフォルダを対象に検索します。
- □ ×
コマンド プロンプト
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
C:\users\user>dir /s *.txt
/b と組み合わせると、見つかったファイルのフルパスだけが表示されるため、ファイルの場所を探すときに便利です。
- □ ×
コマンド プロンプト
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
C:\users\user>dir /s /b *.txt
dir コマンドの主なオプション
/a: 属性で絞り込む
/a:属性 で、指定した属性のファイルやフォルダだけを表示します。属性を指定しない dir では、隠しファイルとシステムファイルは表示されません。
- □ ×
コマンド プロンプト
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
C:\users\user>dir /a:h
| オプション | 説明 |
|---|---|
| /a:d | フォルダのみ |
| /a:-d | ファイルのみ(フォルダ除外) |
| /a:h | 隠しファイル |
| /a:s | システムファイル |
| /a:r | 読み取り専用ファイル |
/b: ファイル名のみ表示
日付やサイズなどの情報を省き、ファイル名とフォルダ名だけを表示します。他のコマンドに渡す場合にも便利です。
- □ ×
コマンド プロンプト
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
C:\users\user>dir /b
/o: 並べ替え
- □ ×
コマンド プロンプト
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
C:\users\user>dir /o:n
| オプション | 説明 |
|---|---|
| /o:n | ファイル名でソート(昇順) |
| /o:-n | ファイル名でソート(降順) |
| /o:s | ファイルサイズでソート(昇順) |
| /o:-s | ファイルサイズでソート(降順) |
| /o:d | 更新日時でソート(昇順) |
| /o:-d | 更新日時でソート(降順) |
まとめ
dirでフォルダの内容を一覧表示し、ワイルドカードで絞り込める/sでサブフォルダも検索でき、/bと組み合わせるとフルパスが得られる/a・/b・/oで、表示対象・表示形式・並び順を調整できる
関連記事
#PowerShell
#コマンドプロンプト
#バッチファイル