Question

I have a script (job A) that runs a Robocopy script to copy all uncompressed .log files from a number of machines each night. I have completed a process (job B) where the .log files are compressed into .7z files prior to job A. As many of the source machines will have a combination of .log and .7z files, I want to set the Robocopy job to move all .7z files to the destination but if there are no .7z files, I want the job to copy the .log files instead.

I have looked briefly at using the IF command but cannot see how to incorporate this fully. I am not sure that this is even possible.

The current job A script is below:

Robocopy "\\SOURCE\Logs" "\\DEST\Logs" /s /zb /r:2 /w:2 /eta /LOG+:\\DEST\\move.log /NP
rem Robocopy "\\SOURCE\Logs" "\\DEST\Logs" *.7z /mov /s /zb /r:2 /w:2 /eta /LOG+:\\DESTmove.log /NP

cls

echo The copy process has finished

Can anyone help?

Was it helpful?

Solution

EDIT: Here is an amended code using the robocopy lines you supplied in the comments and I added a filespec of *.log to the copy version.

It has not been tested.

@echo off
pushd "\\SOURCE\Logs"
if exist *.7z (
    Robocopy "\\SOURCE\Logs" "\\DEST\Logs" *.7z /mov /s /zb /r:2 /w:2 /eta /LOG+:\\DEST\move.log /NP
 ) else (
    Robocopy "\\SOURCE\Logs" "\\DEST\Logs" *.log /s /zb /r:2 /w:2 /eta /LOG+:\\DEST\move.log /NP
)
popd
pause

This is the kind of format you can use: add the two robocopy lines

cd /d "c:\folder"
if exist *.7z (
  echo move files
 ) else (
  echo copy files
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top