0
votes

I'm using the robocopy in batch files that automatic updating our softwares.

that is the command I'm currently use:

ROBOCOPY "%Source%" "%Destination%" /MIR /PURGE /E /NP /R:5 /LOG+:"%Destination%\Update.log" /TS /FP /TEE /XF "%Destination%\SettingsA.config" "%Destination%\SettingsB.config" "%Destination%\SettingsC.config" "%Destination%\Trace.log" "%Destination%\Error.log" "%Destination%\update.log" /XD "%Destination%\Logs"

That command exclude the config and log files, and it's works great.

The problem is that if the config files does not exist, I have to copy the default files from the source directory (%Source%\SettingsA.config, %Source%\SettingsB.config and %Source%\SettingsC.config in that case)

Currently, if that config files will be exist on the source directory they will be overwritten on the destination directory.

Because the source directory is from a mapped network drive it will much better to perform it with a single robocopy command.

Is it possible?

2
What about robocopy"%Source%" "%Destination%" /E /XC /XN /XO /XX …? - aschipfl
@aschipfl It doesn't meet the requirement to install / update the software, it just will copy not existing files. (and will not overwrite the old version) - KBar
Well, what about removing /XO then? or reading the documentation after all? Type robocopy /? into a Command Prompt window and read the help, particularly the File Selection Options section… - aschipfl
Before I went here I have read the documentation well of course, a little bit insulting :) Anyway removing the /XO still will not make it better, I need to overwrite any changed file whether newer or older (excluding the specified config and log files). reinstalling should work that way. The Gerhard's answer is perfect for me now. - KBar

2 Answers

2
votes

To demonstrate what I meant, test each config file for existence, then create a parameter and exclude if it does in fact exist.

if exist "%Destination%\SettingsA.config" set "confa="%Source%\SettingsA.config""
if exist "%Destination%\SettingsB.config" set "confb="%Source%\SettingsB.config""
if exist "%Destination%\SettingsC.config" set "confc="%Source%\SettingsC.config""
ROBOCOPY "%Source%" "%Destination%" /MIR /PURGE /E /NP /R:5 /LOG+:"%Destination%\Update.log" /TS /FP /TEE /XF %confa% %confb% %confc% "%Destination%\SettingsA.config" "%Destination%\SettingsB.config" "%Destination%\SettingsC.config" "%Destination%\Trace.log" "%Destination%\Error.log" "%Destination%\update.log" /XD "%Destination%\Logs"
0
votes

You could just copy source to a temporary directory, move destination to the temp, and move temp to destination.