{"id":9575,"date":"2021-12-02T11:14:18","date_gmt":"2021-12-02T11:14:18","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=9575"},"modified":"2021-12-02T11:15:04","modified_gmt":"2021-12-02T11:15:04","slug":"how-to-read-ini-files-in-win-batch","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/how-to-read-ini-files-in-win-batch\/23672.html","title":{"rendered":"How To Read Ini Files In Win Batch?"},"content":{"rendered":"<p>How to read ini files in windows batch?<\/p>\n<p>Here:\u00a0<a href=\"https:\/\/web.archive.org\/web\/20200812071711\/http:\/\/www.ericphelps.com\/batch\/samples\/getini.txt\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/www.ericphelps.com\/batch\/sam&#8230;<\/a><\/p>\n<p>i find some answer that not satisfy me. So i found better: (we read ini field to batch variable witch only one line of code!)<\/p>\n<p>For example i chave config.ini file:<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-StartFIle<br \/>\n[Remote Machines]<br \/>\nRemoteMachineCompile=&#8221;aaaabbb.ccc&#8221;<br \/>\nRemoteMachineBuild=&#8221;dddd.eee&#8221;<br \/>\nRemoteMachineTest=&#8221;dfffff.ffffe&#8221;<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-EndFile<\/p>\n<p>The answer is:<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-StartFile<br \/>\n@call:ini RemoteMachineBuild var<br \/>\n@echo walue of RemoteMachineBuild is: %var%<br \/>\n@pause<\/p>\n<p>@goto:eof<\/p>\n<p>@REM Function below read config.ini file form current direcotry.<br \/>\n@REM It have 2 parameters:<br \/>\n@REM %~1 &#8211; name of readed ini field,<br \/>\n@REM %~2 &#8211; name var to save readed value.<\/p>\n<p>:ini<br \/>\n@for \/f &#8220;tokens=2 delims==&#8221; %%a in (&#8216;find &#8220;%~1=&#8221; config.ini&#8217;) do @set %~2=%%a<br \/>\n@goto:eof<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-EndFile<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":3},"question-category":[55],"question_tags":[],"class_list":["post-9575","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/9575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=9575"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=9575"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=9575"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=9575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}