use a for /F with if statement

March 9, 2012 at 20:37:04
Specs: Windows XP
I have a list file that end in different "post fix", mean on file might be 123_A and the other being 123_B. I would like to use this batch file to help me sort the files.

Here what i have so far:

@echo off
setlocal enabledelayedexpansion

for /f "tokens=4" %%1 in (List.txt) do (
set filename=%%1
set ex=!filename:~-2,2!

echo !ex!

if !ex!==_a goto fileA
if !ex!==_b goto fileB
if !ex!==_c goto fileC

set file=!filename:~0,-2!
copy C:\files\!file!.mpg E:\Afiles\

set file=!filename:~0,-2!
copy C:\files\!file!.mpg E:\Bfiles\

set file=!filename:~0,-2!
copy C:\files\!file!.mpg E:\Cfiles\

When I run this code it when it meet one of the IF statements it does all of label parts of script, I try to get to do the label part then jump back up to the for statement.

any help will be greatly appreciated

See More: use a for /F with if statement

Report •

March 10, 2012 at 03:56:16
Labels and GOTO statements are forbidden inside a FOR loop. You need to plan your code in a structured way, (gotoless programming) a bit hard but not impossible, or setup the FOR loop using CALL to internal subroutines (see CALL /?).

Report •
Related Solutions

Ask Question