LoginSignup
1
1

More than 1 year has passed since last update.

batファイルで共通設定ファイルを読み込む方法

Posted at

仕事でbatファイルをよく使うので共通の変数を1つのテキストファイルにまとめて、その変数をbatファイルから読み込む方法を書きます。
サンプルとして「c:\設定.txt」という共通設定ファイルを用意しました。
行の先頭に「;」がある場合はコメントアウトとなる様にしています。

共通設定ファイル(c:\設定.txt)
test_file=c:\test.txt
;dummy_path=c:\dummy.txt
out_dir=c:\out
batファイル
@echo off
setlocal

rem 共通設定ファイル読込
for /f "eol=;tokens=1,2 delims==" %%i in (c:\設定.txt) do (
  set %%i=%%j
)

echo %test_file%
echo %dummy_path%
echo %out_dir%

endlocal
pause
結果
c:\test.txt
ECHOは<OFF>です。
c:\out
続行するには何かキーを押してください...

先頭に「;」がある「dummy_path」は読込対象外のため、echoをするとエラーとなります。

1
1
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
1
1