|
Answer» Is there a way to compare two file's (both w/same name) "date modified" using batch file if statement.
The scenario is that I have a file on a c: DRIVE and also located on a network server. If the date modified are different on the two files, I want to copy the file on the network server and replace the file located on the c: drive.
Many thanks in advance, KixThe "xcopy /d" command might work for you. The /d will copy the file only if the source is newer than the destination (or if the destination does not exist). So if you have a file named FILE.TXT that resides on your server Z: drive and your local C: drive, you could do: Code: [Select]xcopy Z:\FILE.TXT C:\ /D /YIf the Z:\FILE.TXT has a newer modified timestamp then it would copy over C:\FILE.TXT. If the C: version had the same or newer date then it would not copy. The /y switch tells xcopy not to prompt you before overwriting the file.Gary,
Thanks so much for your reply.....
I guess I did not include ENOUGH info.. I've looked at xcopy, but not familiar and didn't see where it would do what I wanted in total....
Let me add to the scenario.........
In addition to copying the particular file, I want to also replace another file(s) if the dates are different.... So in essence...if those file dates are different, I want a group of files to be updated on the particular c: drive....
Really....what I'm trying to do is to update a file (front-end of database) on the c:drive, when an update occurs on the network drive. The problem is, that the modified date changes every time the database is opened on the network drive. So my thought is to compare some type of "flag" file, when a PERSON really needs to get a new fron-end of the database (when the actual db is revised)... So I figured I could automatically push out a new "flag-file" when I update the front-end (versus it just being used), and have people run a batch file that looks at the "flag-files" to see if it needs to be updated.....
Make sense?
Any help is appreciated, and thanks so much for your reply KixAre you saying that the front-end database does (or can) create a "flag file", and if that "flag file" exists, then the files should be copied local? Also, are all the files that need to be updated in the same directory? If so, you could do something like this: Code: [Select]if exist z:\FlagFile.txt xcopy z:\src\*.* c:\dest\ /e /h /k /c /YAN example how to perform addtional tasks for each file copied is available at [highlight]http://dostips.cmdtips.com/DtTipsCopy.php[/highlight]
Based on that I guess you would want to do somthing like this: Code: [Select]for /f %%a in ('xcopy "%source%" "%destination%" /D /L /Y') do ( replace ... replace ... xcopy "%%a" "%destination%" /Y )
Hope this helps
|