ROBOCOPY

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
data808
Posts: 47
Joined: 19 Jul 2012 01:49

ROBOCOPY

#1 Post by data808 » 25 Oct 2022 03:43

ROBOCOPY has served me well in batch files for years. I usuaully use something like this:

ROBOCOPY "C:\Users\data8\Desktop\Folder 1" "C:\Users\data8\Desktop\Folder 2" /s

From what I understood, it just basically copies any new or updated files from a source location to the destination that you set. However, tonight I just found out that it will update any file that is has a different modified date and time. Doesn't matter if the file is older, just as long as the modified date or time doesn't match it will replace the destination files. Is there a way to make only update if the files are newer? Tonight I updated a file in folder 1 and then ran the ROBOCOPY batch file to backup Folder 2 to Folder 1 and the file in Folder 1 was backed up with the older file. The newer file is now lost forever I assume. It's a good thing this was just a test but it does scare me. Does anyone know how to prevent this?

Thanks for your time.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ROBOCOPY

#2 Post by aGerman » 25 Oct 2022 09:33

Batch 101:
Press [Windows]+[R] to open the Run box.
Type CMD and hit [Enter] to open a CMD prompt.
Type HELP and hit [ENTER] to get an overview of commonly used commands.
Type <command> /? (e.g. like ROBOCOPY /? in your specific case) and hit [ENTER] to get detailed information about the command.

This having said, I'm aware that the command line options of ROBOCOPY can be overwhelming. However, they are clustered in the help message in order to make it easier for you to find what you're looking for. The "File Selection Options" paragraph states:

Code: Select all

...
                /XC :: eXclude Changed files.
                /XN :: eXclude Newer files.
                /XO :: eXclude Older files.
...
Steffen

data808
Posts: 47
Joined: 19 Jul 2012 01:49

Re: ROBOCOPY

#3 Post by data808 » 25 Oct 2022 12:46

This is very helpful. Thank you!

So if I am using /s with my ROBOCOPY line and I wanted to add /xo to it, would it look like this:

ROBOCOPY "C:\Users\data8\Desktop\Folder 1" "C:\Users\data8\Desktop\Folder 2" /s /xo

Or can you only use one option at a time?

Thanks.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ROBOCOPY

#4 Post by aGerman » 25 Oct 2022 15:41

What's your expectation for a tool with like a hundred options? :lol:

data808
Posts: 47
Joined: 19 Jul 2012 01:49

Re: ROBOCOPY

#5 Post by data808 » 25 Oct 2022 15:56

Oh sorry I was just trying to figure out how to add /xo to the line.

I basically just want ROBOCOPY to copy everything that doesn't exist or files that are newer. So if it's older in the source folder, then do not copy it to the destination folder. I was also thinking of adding /E because then I can have empty directories copied over as well. Do all the options work together if I list it in the code? I would rather check with you before I test in case I mess something up. So if I were to be able to use all 3 options, would the code look something like this:

ROBOCOPY "C:\Users\data8\Desktop\Folder 1" "C:\Users\data8\Desktop\Folder 2" /s /xo /e

Or do I have to separate the options with commas or brackets or something? Like this:

ROBOCOPY "C:\Users\data8\Desktop\Folder 1" "C:\Users\data8\Desktop\Folder 2" /s, /xo, /e
ROBOCOPY "C:\Users\data8\Desktop\Folder 1" "C:\Users\data8\Desktop\Folder 2" [/s] [/xo] [/e]

Sorry if that's a dumb question. Have never used more than one option before.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ROBOCOPY

#6 Post by aGerman » 25 Oct 2022 16:07

You're wasting so much time waiting for response. Be brave and try. And if you are still concerned, write robocopy in the google search box...

data808
Posts: 47
Joined: 19 Jul 2012 01:49

Re: ROBOCOPY

#7 Post by data808 » 25 Oct 2022 17:06

It's ok. I'm at work and have a lot of time. I just check these forums in between my work to change it up a bit. Helps with the boredom.

Thanks for the help. I'll give it a try.

LeoHarrison
Posts: 6
Joined: 20 Feb 2020 04:32

Re: ROBOCOPY

#8 Post by LeoHarrison » 25 Nov 2022 08:37

Why not take all the hassle out of you and to use the easy and effective way, you can use Gs Richcopy or Syncback to copy the newer files only without any loss or errors

Post Reply