InterviewSolution
Saved Bookmarks
| 1. |
Solve : Batch, Replace file if newer? |
|
Answer» HELLO All, Just like the topic states, I am trying to run a batch that will backup a certain file. However at times when the backup runs, the file to be copied is older than the file it will replace, in this case, I would want it not to replace the newer file with the older one. I have attempted the FC command however that seems to be more trouble than help. If someone could show me an example of how to compare file date (and time if possible) then replace as necessary, I would greatly appreciate it. Thanks in advance.First of all, can you provide a copy of the key part of your batch file? Both the COPY command and the XCOPY command have switches to do just what you asked. Unless I'm mistaken, you can just go to the command prompt and type /? After either of those two commands and get a list of options available. But let me ask you why don't you use a standard utility that does exactly what you want with a simple command structure? And why do it at the command prompt? Certainly, let's hope this doesn't further complicate the problem. My CURRENT CODE: Code: [Select]@ECHO OFF TITLE Borderlands Character Backup ECHO Initializing... XCOPY "C:\Users\YourMother\Documents\My Games\Borderlands\SaveData\*" "F:\BackUp\Borderlands\Saves" /y /f /e ECHO Process Completed. The main ISSUE is that it doesn't compare the files date/time before just copying. If I am supposed to use the /D switch with xcopy, what would be the proper syntax for this case? The reason I run this in a batch is for its simplicity and versatility, I can put it anywhere, its standalone and requires no other apps, besides cmd ofc.This is what is says:Code: [Select]/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. Well, did you try this? Code: [Select]XCOPY "C:\Users\YourMother\Documents\My Games\Borderlands\SaveData\*" "F:\BackUp\Borderlands\Saves" /D /y /f /eWell I certainly tried /d:(date) but it had not occurred to me to leave the COLON and date off entirely. I have since tried that, as per your advice, and it works. Thanks again, the cmd help is misleading at times. You can mark this solved. |
|