Solved

robocopy and if else in batch file

Posted on 2010-11-08
6
985 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:YZlat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:cjrmail2k
ID: 34087627
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
0
 
LVL 10

Expert Comment

by:cjrmail2k
ID: 34087636
sorry files _or folders_ that have changed
0
 
LVL 35

Author Comment

by:YZlat
ID: 34087657
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"
0
[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

 
LVL 10

Accepted Solution

by:
cjrmail2k earned 250 total points
ID: 34087694
thats fine, this only copies files that have changed, it wont delete other files as far as I know
0
 
LVL 35

Author Comment

by:YZlat
ID: 34087746
so which switch should I use? /E?
0
 
LVL 10

Expert Comment

by:cjrmail2k
ID: 34088545
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to pick specific file from ftp 13 76
Shell Script on AIX 7 177
How to Remove files with a Date in the Filename with Linux Scripting 3 64
Sleep one hour while in loop 4 43
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question