?
Solved

Checking for the pressence of non empty file in the format YYYYMMDD.txt

Posted on 2004-03-25
8
Medium Priority
?
394 Views
Last Modified: 2010-05-18
Hi

I have the following batch file:-

*********

@ECHO OFF

if NOT exist S:\Download\Clockworx\Datacentre\RUNOK.TXT goto NotOk

c:
cd C:\Program Files\VisionTech\WebBatch
WebBatch.exe
s:
cd s:\Download\Clockworx
Start CLOCKWRX.exe
goto end

:NotOk
@echo The last run has not yet successfully completed, please try again later.
Pause

:end


***********

After the 'webbatch.exe' line, I would like to check for the pressence of a file named in the following format YYMMDDDD.txt  where yyyy is the current year, mm the curent month and dd the current day(and that it's not empty) and go back to the start to try again if not present.  
0
Comment
Question by:IanWood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 10676759
Add this under webwatch.exe

for /f "tokens=1-3 delims=/ " %%a in ('date/t') do set varDate=%%c%%a%%b.txt
if not exist c:\%varDate% %0
0
 

Author Comment

by:IanWood
ID: 10677008
Thanks for the quick reply sirbounty.

Slight problem, this seems to check for 03Thu25.txt rather than 20040325.txt (sorry, just looked back and i had listed the format slightly wrong)?

Cheers!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10677356
Type:
DATE /T
from a command line.
It had to do with your OS.
I believe W2k displays the "day" as well...

Try changing it to tokens=2-4 instead of 1-3...
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:IanWood
ID: 10677456
Cool, getting there with the following:-

for /f "tokens=2-4 delims=/ " %%a in ('date/t') do set varDate=%%c%%b%%a.txt

Almost there, is there an alternative to the 'if not exist' that checks file size and picks up on an empty 0 byte file as well?

Many Thanks! :-)

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10677749
I 'do' like a good challenge... :D

There may be a much better way, and I'm not very happy with this, but maybe it'll work for you...

for /f "tokens=4-5 delims= " %%x in ('dir *.txt') do if [%%y]==[%vardate%] if [%%x]==[0] %0
{space}---------------------^

Make sure there's a space there...

Roughly, what this does...

Create a directory listing of all txt files.
Output of each 'file' line would be
date | time | am/pm | bytes | file

we don't care about date or time, so we start at #4 (bytes).
If the file name (#5) is equal to what we're looking for, then do another comparison:
if the size of that file (#4) is 0 bytes - then run %0 (restart the script).

Hope that helps...I've gotta get going - won't be able to check back until later this evening...

Good luck!
0
 

Author Comment

by:IanWood
ID: 10678819
Thanks for that!

My dir output doesn't seem to have the am/pm, so I've amended as below:-

for /f "tokens=3-4 delims= " %%x in ('dir *.txt') do if [%%y]==[%vardate%] if [%%x]==[0] goto EmptyFile

It seems to be doing the trick nicley so far.. :-)

0
 
LVL 1

Expert Comment

by:pcofranc
ID: 10680036
tip: to clean it up more
assign each search pattern to a variable with set statement

ex set var1=="[%vardate%] if [%%x]"
set var2==

this will simplify your if stmts and make it
easier to try different pattern matching make code more maintaiable.

if var1==var2 do .... etc
0
 
LVL 1

Expert Comment

by:pcofranc
ID: 10680073
another remark consider using free kixtart
or rexx for dos or something.  Dos wasn't designed with these things in mind even thought people find ways to do contortortions to get to do stuff the code is to hard to create/maintain.

kixtart is more real and free but has some issues.  It also does not require an "install" on the pc and a batch file can kick off the install with the exe script engine file in the same dir.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question