@echo off REM fix the files by making rows with all 8 columns setlocal EnableDelayedExpansion set out_file = V_nw_fixed_all.txt For /l %%s in (1, 1, 6) do ( set nr=4 IF %%s equ 1 set nr=5 IF %%s equ 3 set nr=5 echo s and n %%s !nr! For /l %%r in (1,1,!nr!) do ( howardconv.exe "Curve Plane %%s_%%r" V_nw_%%s_%%r_fixed.txtp )) copy *.txtp V_nw_fixed_all.txt echo done!