Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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,

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!

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.

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.

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

![]() |
Ask for name on open & up...
|
Repalce of digits in one ...
|

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