GOTO was unexpected

Focus enhancement Tview micro presenter...
October 28, 2010 at 03:18:50
Specs: Windows XP
Hi batch script guru,
I'm creating a simple batch script but got a unexpected error.

Here is my script:


dir /b /a:a C:\folderA\*.* > C:\fileA.txt

REM read files
FOR /F "tokens=1" %%I IN (C:\fileA.txt) DO (
set variableA=%%I

CALL :CopyFiles
)

:CopyFiles
if %variableA%== "" goto :EOF
REM Copy files starts here REM

---------------------------------------

If i were to comment out the IF statement, the copy script will run.
But I can't figure out what i've done wrong on the IF statement.
If i were to put a doublequote on %variableA% the script will throws an error when its a space in the file.

Appreciate any advice on this.

Thanks.
Joah


See More: GOTO was unexpected

Report •


#1
October 28, 2010 at 03:35:27
Try the script below

dir /b /a:a C:\folderA\*.* > C:\fileA.txt

REM read files
FOR /F "delims=" %%I IN (C:\fileA.txt) DO (
  set variableA=%%~I
  CALL :CopyFiles
)
goto :EOF

:CopyFiles
if  "%variableA%"=="" goto :EOF
REM Copy files starts here REM


Report •

#2
October 28, 2010 at 03:55:17
:: Not obvious where you're going with this.
:: You don't need to create a file from dir output.
:: Nor do you need a sub.

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/aa') do (
echo copy %%a blabla
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#3
October 28, 2010 at 03:57:02
Hi IVO,

Long coffee break.


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
October 28, 2010 at 04:00:53
Better to embrace the copy operands with double quotes since the OP states there are troubles when filenames with blank found, i.e.

copy "%%a" "blablabla"


Report •

#5
October 28, 2010 at 04:30:31
Hi IVO,
Many thanks, works perfectly !

thanks again.


Report •

Ask Question