Solved

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

Posted on 2004-03-25
8
392 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 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get a list of users on network who have folders open 25 59
Automated script task to send email 22 102
Batch: check service status 11 93
Internet Connection Util 8 111
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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