Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

robocopy and if else in batch file

Posted on 2010-11-08
6
Medium Priority
?
1,132 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 10

Accepted Solution

by:
cjrmail2k earned 1000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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 …
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
Suggested Courses

604 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