Simple batch file to compare dates and email

Posted on 2009-02-11
Medium Priority
Last Modified: 2013-11-09
Ok, Who knew this would be so complicated, but I am trying.

So all I want to do is compare 2 files, and email me if one is older then the other, I do this with 2 Batch files, one I got from here on EE, and the other I wrote to use the latter.

My file is the problem I think.  If I use the EE batch form the command line, it works fine, but for some reason the EE batch is not working when I try to pass it commands

the output for the EE batch below is this;


This appears to me like the Arch file is not being processed correctly from the EE batch file, but for the life of me I can't figure out why

:(  please help
-Check.bat file, I made this
echo off
for /f "tokens=*" %%a in ('dir c:\4dBackup\Archaeobase* /b') do set arch=%%a
for /f "tokens=*" %%b in ('dir c:\4dBackup\Ethnobase* /b') do set ethno=%%b
set yesterday=datefile[1].txt
call Check-and-email.bat %arch% %yesterday%
call Check-and-email.bat %ethno% %yesterday%
del /f c:\4dBackup\datefile.txt
dir c:\4dBackup\ /a-d >c:\4dBackup\datefile.txt
- Check-and-email.bat I got this from another post on EE, it works from the command line
echo off
echo %1
echo %2
call :FORMATSTR str1 "%~t1"
call :FORMATSTR str2 "%~t2"
set result="Archaeology-DB Database Backup Failed"
echo %str1%
echo %str2%
if /i "%str1%" GTR "%str2%" (set result="Archaeology-DB Database Backup Suceeded")
blat datefile.txt -t me@here.com -s %result%
goto :EOF
set TestTime=%~2
set TestTime=%TestTime:~6,4%/%TestTime:~0,5%%TestTime:~-2,1%%TestTime:~11,5%
set %1=%TestTime%

Open in new window

Question by:loftyworm
  • 4
  • 3
LVL 21

Expert Comment

ID: 23620262
Shouldn't this line

set yesterday=datefile[1].txt

Be a valid file? I think you named it

set yesterday=datefile.txt
LVL 16

Expert Comment

by:Bryan Butler
ID: 23621642
Are you thinking you have an array here?  If you combine this into one script, and make the loop:

for /f "tokens=*" %%b in ('dir c:\4dBackup\Ethnobase* /b') do set ethno=%%b

call the check each time, then that should work.  
LVL 11

Author Comment

ID: 23624794
The datefile.txt and datefile[1].txt files are to create a file that has a modification time to compare against.  Final version they will match, but in this testing, I have made sure that the files existm the script is not failing at that point.

I am not completely following you.  In a batch script, any for loop variables have to have the %% in front, from the command line you only use one but in a scrip there must be 2.
I do not see how I could combine the two calls, one is working on the arch file and the other is working on the ehtno file.  In any case, I can't even get one ot work.  It passes the datefile modified time, but not the other.  I just tried this command  Check-and-email datefile.txt archaeology[0001].4bk manually, and it still fails.  could the [ ] be the problem?
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

LVL 11

Author Comment

ID: 23624826
This command worked from the command line, just not when I am calling it.
Check-and-email datefile.txt archaeology[0001].4bk
LVL 21

Expert Comment

ID: 23626276
Both scripts are in the c:\4dBackup?
LVL 11

Author Comment

ID: 23626638
No, the are in c:\4dbackup\backup\
that is why I am fully qualifying everything
LVL 21

Accepted Solution

AmazingTech earned 2000 total points
ID: 23627243
That's probably your problem then.

%1 is just the file name so it can't find the file Archaeobase[0001].4BK in your current directory. To get it's date.

Try adding your directory to the path. Make sure the 2 datefile*.txt is in c:\4dbackup
SET PATH=%PATH%;c:\4dbackup\backup
cd /d c:\4dbackup
LVL 11

Author Closing Comment

ID: 31545863

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

831 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