@echo off REM fix the files by making rows with all 8 columns setlocal EnableDelayedExpansion 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 howardconv.exe "Curve Plane %%s_%%r" V_nw_%%s_%%r_fixed.txt )) if exist V_nw_fixed_all.txt ( del V_nw_fixed_all.txt) copy *.txtp V_nw_fixed_all.txt del *.txtp echo done!