Solved

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

Posted on 2004-03-25
8
386 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
  • 3
  • 3
  • 2
8 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 125 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now