{"id":586,"date":"2020-06-23T16:27:55","date_gmt":"2020-06-23T23:27:55","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=586"},"modified":"2020-06-23T16:27:55","modified_gmt":"2020-06-23T23:27:55","slug":"85-how-do-you-loop-in-a-windows-batch-file","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2020\/06\/85-how-do-you-loop-in-a-windows-batch-file\/","title":{"rendered":"#85 How do you loop in a Windows batch file?"},"content":{"rendered":"<p>How do you loop in a Windows batch file?<\/p>\n<p>If you want to do something x times, you can do this:<\/p>\n<p>Example (x = 200):<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nFOR \/L %%A IN (1,1,200) DO (\r\n  ECHO %%A\r\n)\r\n<\/pre>\n<p>1,1,200 means:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nStart = 1\r\nIncrement per step = 1\r\nEnd = 200\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How do you loop in a Windows batch file? If you want to do something x times, you can do this: Example (x = 200): FOR \/L %%A IN (1,1,200) DO ( ECHO %%A ) 1,1,200 means: Start = 1 Increment per step = 1 End = 200<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[17],"tags":[],"class_list":["post-586","post","type-post","status-publish","format-standard","hentry","category-batch"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-9s","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":611,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/08\/92-batch-bat-file-to-update-anaconda\/","url_meta":{"origin":586,"position":0},"title":"#92 Batch (bat) file to update Anaconda","author":"gantovnik","date":"2020-08-13","format":false,"excerpt":"#92 Batch (bat) file to update Anaconda: [code language=\"python\"] REM file: update_conda.bat set root=C:\\ProgramData\\Anaconda3 call %root%\\Scripts\\activate.bat %root% call conda update --all pause [\/code]","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":432,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/07\/windows-batch-script-to-print-nth-lines-after-line-containing-matched-string\/","url_meta":{"origin":586,"position":1},"title":"#63 Batch script to print n-th lines after line containing matched string","author":"gantovnik","date":"2019-07-26","format":false,"excerpt":"[code language=\"python\"] @echo off setlocal enableDelayedExpansion set \"word=VON MISES\" set \"keep=3\" set \"file=model.f06\" find \" X \" model.f06 > extract_weight.txt del extract_stress.txt set n=%keep% for \/f \"usebackq delims=\" %%A in (\"%file%\") do ( set \"ln=%%A\" if \"!ln:%word%=!\" neq \"!ln!\" ( echo( set n=0 ) if !n! lss !keep! ( echo\u2026","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":688,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/09\/121-windows-batch-script-to-run-every-nastran-input-file-in-folder\/","url_meta":{"origin":586,"position":2},"title":"#121: Windows batch script to run every Nastran input file in folder","author":"gantovnik","date":"2020-09-28","format":false,"excerpt":"This is an example of a Windows bat file to run Nastran for every *.dat file in the current folder. It also calculates the total Nastran execution time. Of course, you should change the path to nastran.exe. The nice thing here is that script uses variable set MyPath=%cd%, so you\u2026","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":851,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/151-script-to-create-multi-volume-rar-archive-with-specific-size-of-each-volume\/","url_meta":{"origin":586,"position":3},"title":"#151 Script to create multi-volume rar archive with specific size of each volume","author":"gantovnik","date":"2021-01-27","format":false,"excerpt":"#151 Script to create multi-volume rar archive with a specific size of each volume. I request 3GB for each volume. Create a bat file with the following code: [code language=\"python\"] SET WINRAR=\"C:\\Program Files\\WinRAR\" for \/D %%f in (\"D:\\create_rars\\*\") do ( %WINRAR%\\RAR.exe a -ep1 -r -v3G -idcdp -t -df \"D:\\create_rars\\%%~nxf.rar\" \"%%f\"\u2026","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":601,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/08\/89-windows-batch-bat-script-that-counts-from-10-to-0-by-2\/","url_meta":{"origin":586,"position":4},"title":"#89 Windows batch (bat) script that counts from 10 to 0 by 2","author":"gantovnik","date":"2020-08-13","format":false,"excerpt":"#89 Windows batch (bat) script that counts from 0 to 10 by 2: [code language=\"python\"] for \/l %%B in (10,-2,0) do echo %%B pause [\/code]","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":599,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/08\/88-windows-batch-bat-script-that-counts-from-0-to-10-by-increments-of-2\/","url_meta":{"origin":586,"position":5},"title":"#88 Windows batch (bat) script that counts from 0 to 10 by 2","author":"gantovnik","date":"2020-08-12","format":false,"excerpt":"#88 Windows batch (bat) script that counts from 0 to 10 by 2: [code language=\"python\"] for \/l %%B in (0,2,10) do echo %%B pause [\/code]","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=586"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/586\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}