Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

54
60

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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 はバッチパラメータを一つ繰り上げる。

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

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

参考サイト

54
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
54
60

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?