Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

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=の左側を変数名、右側を値として扱うことが出来ます。
便利。

mik_claire
ド素人なC#er。DBややこしくて死にかけてるひと。 teratailと同時に質問として記事を投稿したりしてます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした