Avatar of YZlat
YZlatFlag for United States of America

asked on 

robocopy and if else in batch file

What I am trying to do is check if a folder Test exists on a desktop and if it does not, then I want to copy that folder from the server. And if it already exists, then I want to just copy the files from folder Test on the server into the existing folder on the desktop. And if existing folder contains any files I don't want the purged.  Below is the if else statement I use and it works great if folder does not exist but does nothing if folder already exists on the desktop. What am I doing wrong?

P.S. I want to use robocopy for copying the folder ot the files

if not exist "C:\Documents and Settings\All Users\Desktop\Test" 
(
robocopy "\\Server03\data\Test" "C:\Documents and Settings\All Users\Desktop\Test" /E
)
else
(
robocopy "\\Server03\data\Test" "C:\Documents and Settings\All Users\Desktop\Test" /COPY:DAT
)

Open in new window

Microsoft DOSShell Scripting

Avatar of undefined
Last Comment
cjrmail2k
Avatar of cjrmail2k
cjrmail2k
Flag of United Kingdom of Great Britain and Northern Ireland image

why not rather use robocopy to copy the whole folder each time, there is a switch that you can use to only copy files that have changed
Avatar of cjrmail2k
cjrmail2k
Flag of United Kingdom of Great Britain and Northern Ireland image

sorry files _or folders_ that have changed
Avatar of YZlat
YZlat
Flag of United States of America image

ASKER

the reason why I can't do that is because if Test folder already exists, it might contain files that are not in "\\Server03\data\Test"
ASKER CERTIFIED SOLUTION
Avatar of cjrmail2k
cjrmail2k
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of YZlat
YZlat
Flag of United States of America image

ASKER

so which switch should I use? /E?
Avatar of cjrmail2k
cjrmail2k
Flag of United Kingdom of Great Britain and Northern Ireland image

think thats it, I can check my scripts when I get in tomorrow and confirm, you can also copy permissions on files etc if you like.
Microsoft DOS
Microsoft DOS

Microsoft Disk Operating System (MS-DOS) was an operating system for x86-based personal computers, and traces of it are still found in the Windows operating system. DOS is still used in some embedded systems and for certain legacy 16-bit networks.

14K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo