Computing.Net > Forums > Programming > batch prog, need help!

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.

batch prog, need help!

Reply to Message Icon

Name: SiCk4
Date: February 11, 2009 at 06:25:20 Pacific
OS: Windows XP
CPU/Ram: core2duo 2G ram
Product: Dell / DELL
Subcategory: Batch
Comment:

Hi Guys, Im new to batch prog, and need help on this:

ECHO * CHECKING INVALID FILES *
IF EXIST "C:\Temp\Zips\*.txt" (
GOTO :GERAINV
:GERAINV
FOR /F "tokens=2-4 delims=/- " %%A IN ('date/T') DO SET inv=%%B%%A%%C
MD "C:\Temp\Zips\invalid\%inv%"
MOVE "C:\Temp\Zips\*" C:\Temp\Zips\invalid\%inv%"
ECHO * INVALID FILES FOUND *
ECHO FOUND INVALID FILES IN C:\Temp\Zips\invalid\%inv% PLEASE CHECK >> C:\Temp\log%inv%.txt
ECHO * END CHECK *
ECHO.
SLEEP 2
GOTO :STREC
) ELSE (
ECHO * NO INVALID FILES FOUND *
ECHO * END CHECK *
ECHO.
SLEEP 1
GOTO :STREC
)

I have two questions about this part of my code:
1) There is a way to put a wildcard on:
"IF EXIST "C:\Temp\Zips\*.txt" "
... instead of only check for text files as I did? (I tried * and *.* but none worked =(

2) There is a way to put the FOR command inside my IF command and remove the "GOTO :GERAINV"? So the code doesn't look so bad as it is... =/

Regards,



Sponsored Link
Ads by Google

Response Number 1
Name: SiCk4
Date: February 12, 2009 at 05:12:47 Pacific
Reply:

I just found out by myself about the wildcard, just had to put a . instead * and it worked =)

Can someone still help me with the second question (howto FOR inside IF)?

Thanks!


0

Response Number 2
Name: Judago
Date: February 12, 2009 at 12:46:52 Pacific
Reply:

I don't see any reason why you can't just remove:

GOTO :GERAINV
:GERAINV


0

Response Number 3
Name: SiCk4
Date: February 12, 2009 at 13:00:29 Pacific
Reply:

Hi Judago,
I dont know y neither, but when I remove the GOTO, it make the script to not work, it just blink\escape. With the GOTO it runs just fine.

Could you post a simple sample of correct usage of FOR inside IF? so I can try to compare with mine? Thank you.


0

Response Number 4
Name: Judago
Date: February 12, 2009 at 23:48:03 Pacific
Reply:

I could post something that I know works but you already have the "for-loop-in-an-if-statement" part right.

The only thing wrong I can see is that you need to use delayed expansion for inv to expand to anything as the whole if statement is treated as one line and variables are only updated with each new line that isn't a grouped statement within brackets. Just add "setlocal enabledelayedexpansion" somewhere above the statement(probably the start of the script) and use !inv! instead of %inv%.

Can you post the whole script, as there is presumably more(:STREC??). I think the problem may be a unclosed bracket or something similar. When doing so can you use pre tags(i.e. paste in your script highlight it and click on the pre button above the text field.). Things like tabs and leading spaces will appear as they should that way.


0

Response Number 5
Name: SiCk4
Date: February 13, 2009 at 02:55:56 Pacific
Reply:

As you said, after including the "setlocal enabledelayedexpansion" and !inv! my script is running just fine now without the GOTO

Thanks Judago


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Ask for name on open & up... Repalce of digits in one ...



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: batch prog, need help!

Batch File --- need help www.computing.net/answers/programming/batch-file-need-help/15889.html

Need help with WinXP batch script www.computing.net/answers/programming/need-help-with-winxp-batch-script/13165.html

Please, I need help so badly www.computing.net/answers/programming/please-i-need-help-so-badly/15937.html