Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
44
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@mik_claire

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

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

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

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
44
Help us understand the problem. What are the problem?