robocopy help please

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miket11
Posts: 2
Joined: 11 Jan 2019 10:55

robocopy help please

#1 Post by miket11 » 11 Jan 2019 11:06

hey guys, hope someone can help me. I want to create a script that can copy files from one folder to another. So the source folder will have files that are updated versions of files in the destination folder.

Its pretty simple to just do the robocopy command but what I want to do is a little different. I don't want to override files in the destination folder. What I want to do is to be able to back up the file in the destination folder that is bout to be overwritten to a different folder

So if Destination folder has files 1 though 10 and the Source folder has File 2,3,4. the robocopy would typically take the files 2,3,4 from source and copy them to destination folder replacing 2,3,4 in destination.

I want it to somehow follow this logic. "if the files with same name exist in the destination folder; first backup the files from destination folder to a different folder and only then copy files from source to destination. I also want the source files to be deleted after they are copied to destination


OR maybe there is a different option? something where robocopy will copy file from source folder to destination folder without overwriting the already existing file and after it copies the file there will be a next line of code that will look at the destination folder and move the older file to a different folder?

Please someone help. Thank you

miket11
Posts: 2
Joined: 11 Jan 2019 10:55

if statements in batch files

#2 Post by miket11 » 11 Jan 2019 12:02

I'm trying to write a batch file using robocopy and if statements.

because I have a lot of files and there is never a specific file name its a little tricky.


a little background on what Im doing so it make a little more sense.

I have a Folder that is located on a shared drive/server, this Folder has files necessary for a certain software. These files are configurable and I or other people in the group can open these files and modify them as needed. Well the thing is I do not want them to save it back to this Folder on the shared driver/server before they are approved.

So what I do is require them to save it to a "Need Approval" folder on their local machine.

I need to make a script that would look at that "Need Approval" folder on each local machine and robocopy files that are in there to "Need Approval" folder on a Shared drive/server

This way I can go to "Need Approval" folder on the shared drive/server and look at files that need to be reviewed and approved. So when I review and approve the files I will move them to "Approved" folder on the Shared drive/server

So, now I need a script to also be able to take files from the "Approved" folder and move them that folder I mentioned in very beginning. That folder that has all the files for the software. This is the main Folder that can not afford to be messed up. which is why I need this whole process.

Here is a catch though. When moving files from "Approved" folder which could be anywhere from 1 file to many I do not want them to just overwrite files in the destination folder (the main important folder)

What I need is an if statement to do something like this.... or maybe some other type of solution

if a file that is about to be copied exists in destination, back it up first to a different folder and then copy.
else if the file that is about to be copied doesn't exist in the destination then go ahead and copy the file

I also need the files to not be replaced with older date files. I want the files to only be copied if there was a change in the files, such as size or date.


SIMMS7400
Posts: 419
Joined: 07 Jan 2016 07:47

Re: robocopy help please

#4 Post by SIMMS7400 » 13 Jan 2019 14:57

Damn Millennials...

Please try a few different things and come back with your results.

pieh-ejdsch
Posts: 176
Joined: 04 Mar 2014 11:14
Location: germany

Re: robocopy help please

#5 Post by pieh-ejdsch » 14 Jan 2019 17:08

Hi,
I have to admit it sounds pretty undecided what you want exactly now.
I do not want to advertise, but maybe this can help you.
viewtopic.php?t=7903#p52948

Post Reply