If-Exist not working in batch file

Microsoft Windows xp professional (upgr...
December 17, 2009 at 22:09:55
Specs: Windows Vista
Hi All

What i want to do is access a notepad, check the file names there in a a for loop.After getting the file name i want to see whether the particular file exists in a certain location.If exists then i want to move to another folder and publish 'file was removed' in the log file.
If not i need to echo the file could not be found.
I tried the following code but the if exist seems not to be working for some reason.

ECHO The files below were removed on > log.txt
date/t >> log.txt
time/t >> log.txt
FOR /F "skip=2 tokens=1,2* delims= " %%i in (C:\Users\kl\Documents\DELETEME\del.txt) do(
If Exist C:\Users\kl\Documents\DELETEME\West\%%i\%%j.txt (
move /y C:\Users\kl\Documents\DELETEME\West\%%i\%%j.txt C:\Users\kl\Documents\TEST & @echo %%i/%%j was deleted >> log.txt
echo. %%i/%%j could not be found >> log.txt

Without the if -else block it works fine.But i need the if-else block to get the complete log file.
Could anyone please help me to find why this is not working?
Thanks a lot in advance!!

See More: If-Exist not working in batch file

Report •

December 18, 2009 at 06:27:56
Should be
) else (

Report •

December 18, 2009 at 07:53:25
Thanks Razor for correcting me but even then some other error is thr.So its not working.
Now i am trying something as below.

sqlplus /nolog @E:\planograms\WPExtract.sql
ECHO The PDFs below were cleaned on > logWPclean.txt
date/t >> logWPclean.txt
time/t >> logWPclean.txt
MD E:\planograms\RemovedPDFs
FOR /F "tokens=1,2* delims= " %%i in (E:\planograms\WpExtract.txt) do(
if Exist E:\planograms\PDFs\%%i\%%j.pdf(
move /y E:\planograms\PDFs\%%i\%%j.pdf E:\planograms\RemovedPDFs & @echo %%i/%%j was removed >>logWPclean.txt
) else (
echo. %%i/%%j could not be found >> logWPclean.txt

Report •

December 18, 2009 at 08:44:17
Actually, you seem to have a space problem in general with your parentheses. Do yourself a favor, and put spaces around every parentheses in that script.

Report •

Related Solutions

December 18, 2009 at 08:46:33
Scripts are rather unforgiving of sloppiness.

some other error is thr.So its

FOR /F "tokens=1,2* delims= " %%i in (E:\planograms\WpExtract.txt) do(

Helping others achieve escape felicity


Report •

December 18, 2009 at 10:30:18
Thanks a lot guys!
This was space problem with parentheses
Its working fine now.

Report •

Ask Question