tags:

views:

41

answers:

2

I'm writing a DOS batch job to review two different directories, identify files with like first six characters, and then move both the matched files to a third directory. I'm getting a syntax error on the following code. Any suggestions?

File 1:

set CopyCount=0


for %%f in (??????*.tif) do call ..\MatchMove1.bat %%f

cd ..

if %CopyCount%==0 goto end

ECHO %date%-%time% %CopyCount% "Matched and Copied" >> MatchMove.log
ECHO %date%-%time% "**************************************************" >> MatchMove.log

echo %CopyCount%

:end

File 2(MatchMove1)

set xFile=%1
set pFile=%xFile:~0,6%

cd..

if not exist "Copy3_Certificates_tiff\%Pfile%*.tif"  PAUSE goto end

copy "Copy4_Working_Documents\%pfile%*.tif" "Copy5_Cert_WorkDoc_Match"
copy "Copy3_Certificates_tiff\%pfile%*.tif" "Copy5_Cert_WorkDoc_Match"

rename "Copy4_Working_Documents\%xFile%" "%xFile%*.cpy"
rename "Copy3_Certificates_tiff\%pfile%*.tif" "%pfile%*.tif.cpy"

ECHO %date%-%time% "Files starting with "%pfile%" copied" >> ..\MatchMove.log

set /a CopyCount =%CopyCount%+1

:end
A: 
I'm getting: '..\MatchMove1.bat' is not recognized as an internal or external command,operable program or batch file

This suggests that it can't find MatchMove1.bat, is it in the parent folder of the folder from where you started the process?

Andy Morris
I'm a dope. No it's not! Thanks. It's still very in-ellegant code, and not running the way it should, but I think I can resolve the rest. Thanks.
Cornelle M
A: 

To avoid this kCind of problems I would put your two .BATs in a single file, using the CALL :label syntax. See HELP CALL.

Also, for your SET commands to properly work, you need to make sure you have enabled delayed expansion. See the HELP SET for an explanation.

Insert this line

SETLOCAL ENABLEDELAYEDEXPANSION

as the first line of your batch file.

and use !CopyCount! instead of %CopyCount% to get the environment variable.

PA