LoginSignup
1
0

More than 3 years have passed since last update.

Batファイルの変数でハマる

Last updated at Posted at 2019-07-08

完全に自分用の覚え書きです。
下書きたまって上限になっちゃったから、とりあえず押し出しです。あらら。

数年に一回しか作らないBatファイル。
そういえば、こんなのありましたね、遅延環境変数。
for文でハマっていたのですが・・・

遅延環境変数
https://blog.natade.net/2018/10/06/windows-bat-%E9%81%85%E5%BB%B6%E7%92%B0%E5%A2%83%E5%A4%89%E6%95%B0-for-if/

ONにすること忘れない
setlocal EnableDelayedExpansion

でも/lはいけるが/fはいけない

どちらかというと、
遅延環境変数の展開を行わずforループ内で変数を参照する方がやりやすいと発覚。

でも結局、動かない動かないと苦しんでいた原因は文法を忘れていたせいだった・・・というオチ。

set listname = list_%*.txt
echo %listname%

(半角スペース)= (半角スペース)

.netに慣れて半角スペース明けが当たり前になってたよ・・・。
そうかBatファイルは受け付けないのか・・・。

あと、このへんも便利

テキストファイルの任意の行を読み込む
https://oshiete.goo.ne.jp/qa/7487016.html

ファイルの行数を数える
https://www.atmarkit.co.jp/ait/articles/1809/20/news031.html

コマンドを変数に入れる
https://hacknote.jp/archives/12683/

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