Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-03-25
8
Medium Priority
?
395 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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