Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch, Replace file if newer  (Read 23168 times)

0 Members and 1 Guest are viewing this topic.

PPowerHouseK

  • Guest
Batch, Replace file if newer
« on: July 03, 2010, 01:11:28 PM »
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.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Batch, Replace file if newer
« Reply #1 on: July 03, 2010, 01:36:36 PM »
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?

PPowerHouseK

  • Guest
Re: Batch, Replace file if newer
« Reply #2 on: July 03, 2010, 01:42:39 PM »
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.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Batch, Replace file if newer
« Reply #3 on: July 03, 2010, 08:00:47 PM »
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 /e

PPowerHouseK

  • Guest
Re: Batch, Replace file if newer
« Reply #4 on: July 06, 2010, 02:32:54 PM »
Well 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.