?
Solved

calculate the seconds between the modification time of a file and the current time

Posted on 2011-03-24
8
Medium Priority
?
492 Views
Last Modified: 2012-05-11
Hi i'm making a batch file to check the current time and the modification time of a file.
Then I want to extract the modification time of the current time, and this is less then 1 minute it needs to exit the program.

I think the code needs to be like this
MODIFICATION=
CURRENT=
DIFFERENCE=CURRENT - MODIFICATION

if difference < 1 minute (
exit
) else (
cd C:\wamp\bin\mysql\mysql5.5.8\bin\
mysqldump -u root test > Databases/test.sql
copy C:\wamp\bin\mysql\mysql5.5.8\bin\Databases\test.sql C:\Users\Maikel\Desktop\GITstage\PDFTool
cd C:\Users\Maikel\Desktop\GITstage\PDFTool
git add test.sql
git commit -m "Updating database"
)
exit

Open in new window


The code after the else is correct, but I don't know how I can calculate the difference between the modification time and the current time.
I know how i can check the modification time of "test.sql". It's done by this
 
@echo off
set "file=C:\Users\Maikel\Desktop\GITstage\PDFTool\test.sql"
for /d %%a in ("%file%") do echo %%~ta

Open in new window


If somebody can help me out, I would appreciate it
0
Comment
Question by:Silencer001
[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
  • 4
  • 4
8 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35205507
Have a look at this script of mine here:

http://scripts.dragon-it.co.uk/links/batch-files-older-than

This is for 20 mins, but change the 20 to 1...

On the way out shortly but if you want help making that work please ask

Steve
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 35205526
Bit more:
@Echo off
for /f %%a in ('cscript //nologo checkfiletime.vbs test.sql') do set check=%%a
if not "%check%"=="OK" (
  echo File is now %check% minutes old
  echo do your stuff here
)


REM Save this as Checkfiletime.vbs
DIM filename, filesys, file1, timediff

If Wscript.Arguments.Count = 0 Then
  Wscript.echo "9999 Error - no file specified"
ELSE
  Set filesys = CreateObject("Scripting.FileSystemObject")
  Set file1 = filesys.GetFile(wscript.arguments(0))
  timediff = int((now - file1.DateCreated) * 60 * 24)
 
  'Send age in minutes back to console:
  if timediff >=1 then
    wscript.echo timediff
  else
    wscript.echo "OK"
  end if

End if
0
 

Author Comment

by:Silencer001
ID: 35205571
Looks nice, i only need to adjust it, so he goes into this folder C:\Users\Maikel\Desktop\GITstage\PDFTool

And needs to check the test.sql file in that folder. If you can help me with adjusting your script that it does that, it would be really great.

Silencer001
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:Silencer001
ID: 35205614
Didn't refreshed, so didn't saw your second comment.
Thanks for the quick response.

Works perfectly, now i just need to do the if structure. I'll leave this open, so if I need extra help I can always ask it directly, when I'm finished with the if structure and it works, I accept your solution and award points :)
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35205996
no problem, just shout if you need more, will be back later.

Steve
0
 

Author Comment

by:Silencer001
ID: 35206047
Steve you're the best ;-)

It works like a charm ;-)
The only thing I changed was
 
timediff = int((now - file1.DateCreated) * 60 * 24)

Open in new window

to
 
timediff = int((now - file1.DateLastModified) * 60 * 24)

Open in new window


Thanks for the quick and 100% helpfull answer ;-)
0
 

Author Closing Comment

by:Silencer001
ID: 35206053
Worked perfect.

Looks at the creation date of the file and extracts this from the date of today.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35206828
Would have helped if I'd read it properly but at least we got there!  No problem.

Steve
0

Featured Post

Four New Appliances. Same Industry-leading Speeds.

But don't take it from us.  The Firebox M370 is Miercom tested and Miercom approved, outperforming its competitors for stateless and stateful traffic throughput scenarios.  Learn more about the M370, M470, M570 and M670 and find the right solution for your organization today!

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

765 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