Solved

Date file modified for comparison

Posted on 2008-10-24
4
2,062 Views
Last Modified: 2009-08-24
I have the below batch file to compare the date of a flag file to the system date and shut down a program if the flag file is the same date as the system date, or check to see if the flag file has been updated 10 minutes later.

The IF line exits the process.  When I ECHO the whole batch file, it looks like dt is taking its value from the contents of the file, rather than from the attributes.  How do I get the modified date of the file, or cast a string to a date?

[CODE]
REM @echo off

:loop
REM set variable to flag file mod date in sys format
for /f "tokens=1,2" %%i in (C:\Admin\flag.txt) do (
   set dt=%%i %%j
   )
REM echo %dt%
pause
REM compare flag mod date to sys date
if %dt% equ %date% GOTO indexer
pause
echo Not Equal
REM dates not same so wait 10 minutes and try again
ping -n 601 localhost > nul
pause
GOTO loop

:indexer
pause
echo Equal
REM dates same so close Indexer
CALL C:\Admin\EndIndex.bat
pause
REM wait for fileserver to come back up
ping -n 11 localhost > nul
REM start Indexer again
CALL C:\Admin\StartIndex.bat

EXIT
[/CODE]
0
Comment
Question by:NCHCIT
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
PaulKeating earned 250 total points
ID: 22802121
Your FOR /F is looking at the contents of the file C:\Admin\flag.txt.

Try this:

REM set variable to flag file mod date/time in sys format

for %%i in (C:\Admin\flag.txt) do set dt=%%~ti

REM set variable to date only

for /f "tokens=1" %%i in ('echo %dt%') do set dt=%%i

Open in new window

0
 

Author Comment

by:NCHCIT
ID: 22814114
Thank you.  You've answered my question, but my problem still exists.  The program exits at the IF line.
0
 
LVL 5

Expert Comment

by:PaulKeating
ID: 22824098
>> The program exits at the IF line.

Presumably with an error message, which you haven't told me.

That may depend on how you format your date. Try

if "%dt%" equ "%date%" GOTO indexer
0
 

Author Comment

by:NCHCIT
ID: 22834234
This novice got a helpful hint - run the batch file from a command prompt rather than executing it through Windows.  That gave me the error, and in turn I was able to resolve the issue (the space in the ddd mm/dd/yyyy was causing issues).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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