KBar
KBar

Reputation: 100

Using the robocopy to copy specific files just if NOT exist

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?

Upvotes: 1

Views: 2308

Answers (2)

user7818749
user7818749

Reputation:

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"

Upvotes: 2

Hrisip
Hrisip

Reputation: 920

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

Upvotes: 0

Related Questions