Solved

robocopy and if else in batch file

Posted on 2010-11-08
6
876 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now