BATCH FILE EXPERT NEEDED!

Scenario: 2 servers- SERV1 & SERV2. SERV1 is the master or template server. The D: drive on SERV1 has 3 directories named BLUE, GREEN, & RED. Inside these 3 directories there are dozens of other files.

GOAL: To create a batch file that when run on SERV2 will create the 3 directories(BLUE, GREEN & RED) and then copy the contents of those 3 directories to the newly created BLUE, GREEN & RED on SERV2 via UNC paths, copy commands or whatever else. In the end , if the batch file works properly it will duplicate the contents of the D: drive onto SERV2. It is safe to assume the D: drive has been sized and partitioned before this batch file is run.

I need the actual commands that a pro would use line by line.
Brian_BlairAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
If NOT Exists "d:\blue" mkdir "blue" "green" "red"
copy "\\serv1\sharename\blue\*.*" "d:\blue"
copy "\\serv1\sharename\green\*.*" "d:\green"
copy "\\serv1\sharename\red\*.*" "d:\red"



The above should do it... but there are more questions.  Do these folders have sub folders?  If so, you'll probably want to use XCOPY or ROBOCOPY.  Do these files have security that needs to be copied?
0
Brian_BlairAuthor Commented:
YES- there are definately sub folders. Never really thought about the security but in a perfect scenario, yes the security would be copied.
0
Lee W, MVPTechnology and Business Process AdvisorCommented:
If NOT Exists "d:\blue" mkdir "blue" "green" "red"
xcopy "\\serv1\sharename\blue\*.*" "d:\blue" /o /h /e /v /c
xcopy "\\serv1\sharename\green\*.*" "d:\green" /o /h /e /v /c
xcopy "\\serv1\sharename\red\*.*" "d:\red" /o /h /e /v /c

/e = copies folders and subfolders, even empty ones
/o = copies file ownership and security info
/h = copies hidden and system files
/c = continues copying on errors
/v = verifies each file.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Brian_BlairAuthor Commented:
leew- Thanks for the help. At the top of the file do I need any "cls" statements or "cd" change directory statements? Also, in some of your text you have "quotation" marks. Is this the correct syntax?

Get back to me on this and the points are yours.
0
Lee W, MVPTechnology and Business Process AdvisorCommented:
cls only clears the screen.  You can if you like..  Really doesn't have any relevence to the script other than starting on a blank screen.  TECHNICALLY, you don't need the quotes if those are really the folder/file names you are using.  But they don't hurt.  I included them in case you want to modify this and use folder names with spaces.  When you reference shares/folder names with spaces, you get  errors if they are not in quotes.

No need to CD anywhere, all the paths given are absolute.  Other than perhaps opening a command prompt and CD'ing to the folder you have the script in.  But that can be remedied by put a shortcut on your desktop to wherever you save it.

Also, if you want to log this to save the results of the copy process, you can do the following.

1.  Save the script as - for example: COPIER.CMD
2.  From a command prompt, type COPIER > %temp%\COPIER.LOG

#2 creates a file in your temp folder that has ALL output from the command.  You can review it after the command completes and verify that ALL files were copied and see which - if any - had errors.

If the log is unimportant to you, you would simply type "COPIER"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lee W, MVPTechnology and Business Process AdvisorCommented:
One more note - to create a log that records errors, I made a mistake - you should use:

COPIER > %temp%\COPIER.LOG 2>&1

Otherwise, some programs might not save the errors to the log file.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Networking

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.