what's wrong with my batch file?

June 22, 2009 at 02:39:34
Specs: Windows XP, 3.4
what's wrong with my batch file?

hi there
i have a batch file that should search for 3 (or more) files and if found them goto specified command

@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%A in ('dir /b _344a.jpg;final.jpg;_halph.png') do (
set fileName=%%A
if "!fileName!" equ "" (set goto found) ELSE (set goto notfound)
:found
some commands
:notfound
some commands
)

can you test it please? you can replace those last 4 fines with below lines to see result faster

:found
echo> yes.txt
:notfound
echo> no.txt

why both (txt) file create?
i want if files found correct command execute and not both of them. what's wrong?
can you fix it or write a new batch file for me please?
thanks


See More: whats wrong with my batch file?

Report •


#1
June 22, 2009 at 03:01:37
Here a batch script that should work. You can't code GOTOs inside a For loop. More it seems you do not understand the basic principles of batch scripting. Study, study, study.

@echo off
for %%j in (344a.jpg final.jpg _halph.png) do (
  if exist "%%j" (
    echo.  %%j found
  ) else (
    echo.  %%j NOT found
  )
)


Report •

#2
June 22, 2009 at 04:11:15
thanks but i need goto
what should i do?

Report •

#3
June 22, 2009 at 05:34:36
You cannot mix FOR and GOTO.

Besides, this seems like an overly complicated way around IF EXIST

EDIT: VVV I have no idea what you're talking about, and now I'm confused. VVV


Report •

Related Solutions

#4
June 22, 2009 at 05:42:51
Well, batch scripting is indeed B-programming, but there are B-movies awarded in Hall of Fame as "The Invasion of Body Snatchers". Others are just trash. The script we are talking about belongs to the last category.

Report •


Ask Question