batch prog, need help!

Dell DELL
February 11, 2009 at 06:25:20
Specs: Windows XP, core2duo 2G ram
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,


See More: batch prog, need help!

Report •


#1
February 12, 2009 at 05:12:47
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!


Report •

#2
February 12, 2009 at 12:46:52
I don't see any reason why you can't just remove:

GOTO :GERAINV
:GERAINV


Report •

#3
February 12, 2009 at 13:00:29
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.


Report •

Related Solutions

#4
February 12, 2009 at 23:48:03
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.


Report •

#5
February 13, 2009 at 02:55:56
As you said, after including the "setlocal enabledelayedexpansion" and !inv! my script is running just fine now without the GOTO

Thanks Judago


Report •


Ask Question