{"id":5796,"date":"2021-11-16T14:19:44","date_gmt":"2021-11-16T14:19:44","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=5796"},"modified":"2021-11-16T14:21:05","modified_gmt":"2021-11-16T14:21:05","slug":"batch-file-for-f-loop-only-doing-last-item","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/batch-file-for-f-loop-only-doing-last-item\/21997.html","title":{"rendered":"Batch File For \/F Loop Only Doing Last Item"},"content":{"rendered":"<p>Good morning<\/p>\n<p>I&#8217;ve got an incredibly long-winded (too long to post here, unfortunately, so it&#8217;s more a general question) batch file that contains<\/p>\n<p>&nbsp;<\/p>\n<pre>FOR \/F %%G IN (e:\\apps\\dw\\dump\\pending_trn.txt) DO (\r\n...do stuff here...\r\n)\r\n<\/pre>\n<p>The pending_trn.txt file just contains numbers<\/p>\n<p>8000003<br \/>\n8000070<br \/>\n8000912<\/p>\n<p>The aim of this is to loop through each item in the file, kicking out a text file with further information on the transaction. So I&#8217;d expect to see in the target directory text files called text.8000003 and text.8000070 and text.8000912<\/p>\n<p>But for some reason it only works on the last item in the file, ie. the only textfile that is created is text.8000912<\/p>\n<p>I&#8217;ve got a line in the batch file that says<\/p>\n<p>&nbsp;<\/p>\n<pre>SETLOCAL EnableDelayedExpansion<\/pre>\n<p>Can you guys think of any other reason that the FOR \/F loop would only complete the last item in the source file?<\/p>\n<p>Many Thanks in advance<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":11},"question-category":[55],"question_tags":[],"class_list":["post-5796","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\/5796","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=5796"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=5796"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=5796"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=5796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}