Solved

robocopy and if else in batch file

Posted on 2010-11-08
6
853 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Utilizing an array to gracefully append to a list of EmailAddresses
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

11 Experts available now in Live!

Get 1:1 Help Now