Solved

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

Posted on 2004-03-25
8
390 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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