0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

dirコマンドでファイルパスの一覧を出力する

Last updated at Posted at 2024-10-12

dirコマンドでファイルパスの一覧を出力する

dir /S /B C:\Path\To\Target

実行結果:

C:\Path\To\Target\aaa.txt
C:\path\To\Target\DIR1
C:\path\To\Target\DIR1\bbb.txt
C:\path\To\Target\DIR1\DIR2
C:\path\To\Target\DIR1\DIR2\ccc.txt
  • /S : サブディレクトリを再帰的に探索する
  • /B : パスのみを表示する (見出しを表示しない)

対象を指定する

例1. ファイルのみを対象とする。

dir /S /B /A-D C:\Path\To\Target

例2. フォルダのみを対象とする

dir /S /B /AD C:\Path\To\Target
  • /A : 属性を指定する
    • D : フォルダのみ
    • -D : フォルダ以外 = ファイルの身

例3. 拡張子を指定する

dir /S /B /A-D C:\Path\To\Target\*.jar

FORでループする

@ECHO OFF

FOR /F %%F IN ('dir /B /S C:\Path\To\Target') do (
  ECHO %%F
)

環境情報

C:\>ver

Microsoft Windows [Version 10.0.22631.4169]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?