Solved

robocopy and if else in batch file

Posted on 2010-11-08
6
908 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
  • 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

777 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