Computing.Net > Forums > Programming > what's wrong with my batch file?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

what's wrong with my batch file?

Reply to Message Icon

Name: niki chan
Date: June 22, 2009 at 02:39:34 Pacific
OS: Windows XP
CPU/Ram: 3.4
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 22, 2009 at 03:01:37 Pacific
Reply:

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
  )
)


0

Response Number 2
Name: niki chan
Date: June 22, 2009 at 04:11:15 Pacific
Reply:

thanks but i need goto
what should i do?


0

Response Number 3
Name: Razor2.3
Date: June 22, 2009 at 05:34:36 Pacific
Reply:

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


0

Response Number 4
Name: IVO
Date: June 22, 2009 at 05:42:51 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: what's wrong with my batch file?

Batch file ping.exe errorlevel? www.computing.net/answers/programming/batch-file-pingexe-errorlevel/14655.html

What's wrong with this www.computing.net/answers/programming/whats-wrong-with-this/17542.html

Please review for me (batch file) www.computing.net/answers/programming/please-review-for-me-batch-file/14716.html