コマンドプロンプト dirコマンドを再帰的に実行する

コマンドプロンプト dirコマンドを再帰的に実行する

コマンドプロンプトでdirコマンドを再帰的に実行する手順を記述してます。

環境

  • OS windows10 pro 64bit

再帰的に実行

dirコマンドを再帰的に実行するには、オプション「/s /b」を使用します。

dir /s /b

<出力結果>
C:\hoge\foo
C:\hoge\foo.txt
C:\hoge\index.html
C:\hoge\foo\bar
C:\hoge\foo\test1.txt
C:\hoge\foo\test2.txt
C:\hoge\foo\test3.txt
C:\hoge\foo\bar\sample1.txt

サブディレクトリ内まで表示されていることが確認できます。

ファイルのみの表示したい場合は、「/a-d」を使用します。

dir /s /b /a-d

<出力結果>
C:\hoge\foo.txt
C:\hoge\index.html
C:\hoge\foo\test1.txt
C:\hoge\foo\test2.txt
C:\hoge\foo\test3.txt
C:\hoge\foo\bar\sample1.txt

フォルダのみを表示する場合は、「/ad」とします。

dir /s /b /ad

<出力結果>
C:\hoge\foo
C:\hoge\foo\bar