LoginSignup
55
60

More than 5 years have passed since last update.

【Windows】バッチファイルのコマンドライン引数

Last updated at Posted at 2014-08-06

コマンドライン引数

引数 説明
%0 バッチファイル名
%1~%9 1番目~9番目の引数
%* すべての引数

ループ処理

コマンドライン引数を順に出力。

●スマートな方法

※ngyukiさんから頂いた情報。

@echo off

for %%f in (%*) do (
  echo %%f
)

●別の方法

@echo off

:loop

if "%~1" == "" goto end

echo %1

shift

goto loop

:end

pause

※"%~1" は全ての引用符(")を削除して展開する。
※shift はバッチパラメータを一つ繰り上げる。

ファイルのドラッグ&ドロップ

エクスプローラ上で、複数のファイルをバッチファイルにドラッグ&ドロップすることで、
それらのファイル名がバッチファイルに渡される。
上記ループ処理を使って、ファイルごとに処理を行える。

参考サイト

55
60
2

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
55
60