Page 1 of 1

ROBOCOPY

Posted: 25 Oct 2022 03:43
by data808
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.

Re: ROBOCOPY

Posted: 25 Oct 2022 09:33
by aGerman
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

Re: ROBOCOPY

Posted: 25 Oct 2022 12:46
by data808
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.

Re: ROBOCOPY

Posted: 25 Oct 2022 15:41
by aGerman
What's your expectation for a tool with like a hundred options? :lol:

Re: ROBOCOPY

Posted: 25 Oct 2022 15:56
by data808
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.

Re: ROBOCOPY

Posted: 25 Oct 2022 16:07
by aGerman
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...

Re: ROBOCOPY

Posted: 25 Oct 2022 17:06
by data808
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.

Re: ROBOCOPY

Posted: 25 Nov 2022 08:37
by LeoHarrison
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