Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about a batch file.

Status
Not open for further replies.

montejr

Programmer
May 24, 2001
42
0
0
US
Hello all,
I am hoping that I am posting this in the appropriate forum. I have a simple batch file that copies files from one folder to another. Here it is:

echo on
cd \esri\esridata\usacopy states.sbn c:\temp
copy states.sbx c:\temp
copy states.shp c:\temp
copy states.shx c:\temp
copy states.dbf c:\temp
copy states.prj c:\temp
exit

Is there a way that I could modify the following code to copy only the most recent files - by this I mean the most recently updated files?

Thanks,
Michael
 
You'll have to write a script that reviews the created/modified dates then copies the respective files.

One really nasty ugly way around it is.........

Backup Software
You could use back up software, back up the USA folder to C:\temp, then use a differential backup each day to restore the information just from that day. The differential backup with specifically review the files and back up only the ones that have been modified that day.

I HIGHLY suggest that if you use a scheduled back to do this, it will run COMPLETELY independant of network scheduled backups that you or your engineers have put in place. Check with Management first if you aren't "them."

:)

Good Luck,

Syty
 
Here is a good push in the right direction:
If you manipulate this IF statement:

IF "%NOWDATE%"=="%CHKDATE%" ECHO %1 was created or modified today (%NOWDATE%)

you might get exactly what you were looking for. I've found alot of great help at this site. Hope this helps!

X
 
You might could use XCOPY, like this:
Code:
xcopy states.* c:\temp /d
The /D parameter is defined as this:
/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.

 
cd \esri\esridata\usaxcopy *.* /i/d/f/h/r/k/s/e/v/y C:\TEMP

Will ONLY copy new file and overwrite updated files, giving you always the latest version.

Marc
[sub]If 'something' 'somewhere' gives 'some' error, expect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
[/sub]
 
OK, I couldn't get my link to work. I copied the code from the site I gave previously (with much respect to the Author... for this is not my creation). You can manipulate this and get exactly what you need.

ECHO OFF
REM * MODIFIED.BAT, Version 1.01
REM * Check if specified file was created or modified today
REM * Written by Rob van der Woude
REM *
REM * Needs write access to current directory; or add fully qualified
REM * path to files CURRENT.BAT and its language dependent versions,
REM * and make sure its path is specified in the PATH variable.

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
REM * For Dutch DOS versions
ECHO SET CHKDATE=%%5>VOER.BAT
ECHO SET CHKDATE=%%6>TYP.BAT
CALL %TEMP%.\~ISMODIF.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
REM * For Dutch DOS versions
ECHO SET NOWDATE=%%5>VOER.BAT
ECHO SET NOWDATE=%%6>TYP.BAT
CALL %TEMP%.\~ISMODIF.BAT

REM * Compare dates and display result
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=
GOTO End

:Syntax
ECHO MODIFIED, Version 1.01
ECHO Check if specified file was created or modified today
ECHO Written by Rob van der Woude
ECHO ECHO.
ECHO.
ECHO Usage: %0 filename

:End
 
Although a nice tracking by date copy. that is not really what montejr asked for.
He just wanted the latest version copied, no more.
Unless he changed his mind now ...
 
Thanks to everybody for the posts. They were very, very helpful.

Cheers,
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top