Batch Date and Time Loop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way for a batch file to look inside a specified directory and then
look at the date and time a file was created.

I want to be able to say if x was created to day run this script, i want it
to loop back and say ok this was created to day was this created after xtime
or is it the same file. If it was created on this day and after this time the
orginal was created then do this other wise keep looking in this directory.
 
mirokuu said:
Is there a way for a batch file to look inside a specified directory and then
look at the date and time a file was created.

I want to be able to say if x was created to day run this script, i want it
to loop back and say ok this was created to day was this created after xtime
or is it the same file. If it was created on this day and after this time the
orginal was created then do this other wise keep looking in this
directory.

What you require can be done but you do need to
post the batch file your friend sent you.
 
@ECHO OFF


REM * File name should be specified
IF "%1"=="" GOTO Syntax
IF NOT EXIST %1 GOTO Syntax

REM * Send DIR output for specified file to primary temporary
REM * batch file to get the file's creation or modification date
DIR %1 | FIND /I "%1" > %TEMP%.\~ISMODIF.TMP
ECHO.>> %TEMP%.\~ISMODIF.TMP
TYPE %TEMP%.\~ISMODIF.TMP | TIME | FIND /I "%1" > %TEMP%.\~ISMODIF.BAT



REM * Create secondary temporary batch files to be called by primary
ECHO SET CHKDATE=%%4>ENTER.BAT
ECHO SET CHKDATE=%%4>ENTER.BAT





REM * Send DIR output for temporary batch file to itself to get today's date
DIR %TEMP%.\~ISMODIF.BAT | FIND /I "~ISMODIF.BAT" > %TEMP%.\~ISMODIF.TMP
ECHO.>> %TEMP%.\~ISMODIF.TMP
TYPE %TEMP%.\~ISMODIF.TMP | TIME | FIND /I "~ISMODIF.BAT" >
%TEMP%.\~ISMODIF.BAT



REM * Create secondary temporary batch files to be called by primary
ECHO SET NOWDATE=%%4>ENTER.BAT
ECHO SET NOWDATE=%%4>ENTER.BAT




REM * Compare dates and display result
IF "%NOWDATE%"=="%CHKDATE%" ECHO %1 was created or modified today (%NOWDATE%)
IF "%NOWDATE%"=="%CHKDATE%" ECHO %1 was created or modified today (%NOWDATE%)


REM * Clean up the mess
DEL %TEMP%.\~ISMODIF.BAT
DEL %TEMP%.\~ISMODIF.TMP
DEL ENTER.BAT
DEL VOER.BAT
DEL TYP.BAT
SET CHKDATE=
SET NOWDATE=
SET CHKDATE=
SET NOWDATE=
GOTO End

:Syntax
ECHO MODIFIED.BAT
ECHO Check if specified file was created or modified today
ECHO.
ECHO.
ECHO Usage: %0 filename

:End


The above batch is the one that checks for date i believe and the below is
the one that backs up folder that i need to run if conditions are true:


@echo off
:: variables
set mini= start /min
set backupcmd=xcopy /s /c /d /e /h /i /r /y /q
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%


%mini% %backupcmd% "C:\Dell" "N:\DATA\QC\P101267\%folder%\backup"
Net Send RDecook "Files has been backedup"
 
While I was able to pick up some of the author's ideas in his
batch file, I was unable to get the complete picture. Rather than
attempting to reverse engineer it, I ask you to tell us in a few
examples what you're trying to achieve. Your description in
your original post is not sufficiently clear to provide a good
understanding.

Here is what I had in mind:

1. Examine each file in the current directory.
2. If the file was created yesterday then do ...
3. If the file was created more than two hours ago then do..
4. If the file was created less than one hour ago then do ...

Now replace the above rules with your own words.
 
I hope this is what you are looking For:

1.) I want it to examine the Time & Date Of the files
2.) Store that date & time then run the backup
3.) I want it to examine the Time & Date and compare it with the previous
Time & Date
4.) If that Time & Date are the same then do Nothing
5.) If that Time & Date is greater such as if the file was first examed on
3.28.07 at 9am the first time and the second time it was 3.28.07 at 10 am run
the backup again.


Does that make sense at all?? If not i will try and explain that better.
 
If I understand you correctly then you wish to back up
all files that have changed since the last backup. This
can be achieved with the following lines that are largely
taken from your own example:

@echo off
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
start /min xcopy /s /c /a /e /h /r /y /q "C:\Dell"
"N:\DATA\QC\P101267\%folder%\backup\"
Net Send RDecook "Files have been backed up"
 
Yes but, I need this backup to run each time the file has changed. For example:

If i record x has been backed up at 2.28.07 at 9am and then sam changes the
file and saves it and the time changes or the date on this record it
automaticly runs that backup again.
 
Oh ok thanks alot. I try that.
So then it dosnt actually check for the date it will just back up that
folder each time every 5 mins correct.

Thanks for having so much patiences with me and your help.
 
No, the batch file won't check the date or the time. However,
it will check and reset the "archive" flag of each file.
 
What command resets this arcive bit??? Does this automaticly overright the
files that are currently stored in the backup directory?
 
i see the switch inside xcopy that does that. Again i like to thank you for
your time and help.
 
Back
Top