|
Answer» Hi, I have a problem I need some help with. I have a bat file that kicks off a java program each night. The Java takes an import of a TEXT file. I need to check that the text file was created today before calling the java program....so something like:
X1 = date text file creation date if x1 == today goto loadtxt exit :loadtxt call java prog exit
Any ideas??Try this code:
@echo off set today=%date:~-10% dir /tc Myfile.txt | find "%today%" if errorlevel 1 exit java MyClass exitSaw you USED the statement... set today=[highlight]%date:~-10% [/highlight]
How or what is "%date:~-10%" and how does it work. I've used 'date /t' before but never seen what you used before now. Also, what are the errorlevels used with the DIR command (and or where can I find them).
Have a task that requires I interogate the creation date and stumbled across your post while looking for ideas/solutions.
CHEERS, Cameron set today=%date:~-10%
would extract the last 10 characters of the Date variable.
The errorlevel refers not to the DIR command but the FIND command. It's always the command closest to the ERRORLEVEL check. In this case errorlevel 0 is a successful FIND, errorlevel 1 is a not so successful FIND. When checking errorlevels, always do so in reverse sequence...the actual compare is equal to or greater than.
Example: Code: [Select]find /i "help" file.txt if errorlevel 1 exit if errorlevel 0 goto found :found . . .
In general, errorlvel 0 means successful, anything else is unsuccessful. There are exceptions to every rule. Check the web for details on individual commands.
Happy computing. 8-)Thanks Sidewinder. Noticed the use of %date:~-10% (or similar) when I checked out the set command (neat stuff).
Thanks for the review regarding the errorlevel - I just plainly didn't read the full statement (with the pipe).
|