49
53

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.

【bat】外部ファイルの変数と値を読み込んで使用する

Posted at

備忘録。
バッチファイル書いてるとき、よく外部ファイルから設定を読み込みたくなる瞬間があると思うんですけども。
そういう時にやる方法。

setting.ini
; IP Address
IPAddress=192.168.11.1
; My Name
Name=mikaze
; Text Path
TextPath=C:\Users\mikaze\Desktop\text.txt
main.bat
@echo off
title Main
setlocal enabledelayedexpansion

for /f "tokens=1,* delims==" %%a in (setting.ini) do (
    set %%a=%%b
)

rem 処理

こうしておくと、setting.ini=の左側を変数名、右側を値として扱うことが出来ます。
便利。

49
53
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
49
53

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?