Solved

copy multiple files from multiple subdirectories to different location

Posted on 2011-02-18
9
686 Views
Last Modified: 2012-06-21
URGENT, Please Help - I need to script (with my basic knowledge of cmd, bat scripting) a file copy from one server to another server.  I need to include part of the source's folder (directory) structure where the folder name changes as do the files.  See example below
(Source destination could be mapped drive or UNC) + (Ideally would like to supply the multiple directories & files (1DC\0000AD30.017) in source (txt) file)

Example:
Source
\\server1\directory1\directory2\1DC\0000AD30.017
\\server1\directory1\directory2\1DE\0000AD32.001
\\server1\directory1\directory2\1DE\0000AD32.002
\\server1\directory1\directory2\1E2\0000AD36.001
\\server1\directory1\directory2\1E2\0000AD36.002
\\server1\directory1\directory2\1E3\0000AD37.001
\\server1\directory1\directory2\1E4\0000AD38.001
\\server1\directory1\directory2\1E5\0000AD39.001
\\server1\directory1\directory2\1E6\0000AD3A.001

Destination:
\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1DC\0000AD30.017
\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1DE\0000AD32.001
\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1DE\0000AD32.002
\\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E2\0000AD36.001
\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E2\0000AD36.002
\\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E3\0000AD37.001
\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E4\0000AD38.001
\\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E5\0000AD39.001
\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E6\0000AD3A.001
Any assistance will be most greatly appreciated. Cheers

0
Comment
Question by:flannk
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 1

Expert Comment

by:ceesios
ID: 34931892
Hi there,

try this. You can leave out the domain part if you don't use it.
net use \\server1\ /user:domain\username password
net use \\server2\ /user:domain\username password

copy \\server1\directory1\directory2\1DC\0000AD30.017 \\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1DC\0000AD30.017
copy \\server1\directory1\directory2\1DE\0000AD32.001 \\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1DE\0000AD32.001
copy \\server1\directory1\directory2\1DE\0000AD32.002 \\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1DE\0000AD32.002
copy \\server1\directory1\directory2\1E2\0000AD36.001 \\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E2\0000AD36.001
copy \\server1\directory1\directory2\1E2\0000AD36.002 \\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E2\0000AD36.002
copy \\server1\directory1\directory2\1E3\0000AD37.001 \\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E3\0000AD37.001
copy \\server1\directory1\directory2\1E4\0000AD38.001 \\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E4\0000AD38.001
copy \\server1\directory1\directory2\1E5\0000AD39.001 \\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E5\0000AD39.001
copy \\server1\directory1\directory2\1E6\0000AD3A.001 \\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1E6\0000AD3A.001

Open in new window

0
 

Author Comment

by:flannk
ID: 34932022
Thanks I will test.  One extra question thou, What would the switch be to create the  "1DC", "1DE", etc directory if it doesn't already exist in the destination?
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 34932299
MD is Command for create Directory

MD \\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\1DC

0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 6

Expert Comment

by:Draxonic
ID: 34932333
Put your source files in inputfile.txt and run this is a batch file:

net use \\server1\ /user:domain\username password
net use \\server2\ /user:domain\username password

FOR /F "usebackq delims=\ tokens=1-5" %%i in (inputfile.txt) do (

xcopy "%%i\%%j\%%k\%%l\%%m" "\\server2\diffdirectory1\diffdirectory2\diffdirectory3\%%l\%%m"
)

Open in new window

0
 
LVL 6

Expert Comment

by:Draxonic
ID: 34932347
The xcopy command in the above script will create the destination path structure automatically.

It may need a little tweaking depending on the number of variables in your actual path. *shrug*

This may be overcomplicating it though. If you use ceesios script with xcopy instead of copy, it will create the destination structure but will need more work if the files names change all the time.
0
 

Author Comment

by:flannk
ID: 34932376
The copy command above won't work if it doesn't create the directories (like 1DC, 1DE, 1E2)   as I need the files in these directories and they may not already exist.
0
 
LVL 1

Expert Comment

by:ceesios
ID: 34932454
The xcopy command from Draxonic should fix that, just replace copy with xcopy.
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 34934799
Sincce you have a single source and destination folder each, a more dynamic and less delicate approach can be chosen. You just need to provide source and destination (root) folders, and a list of files with full source path in c:\filelist.txt (or whichever file you want to use):
@echo off
setlocal EnableDelayedExpansion
set source=\\server1\directory1\directory2\
set dest=\\server2\diffdirectory1\diffdirectory2\diffdirectory3\diffdirectory4\
for /F "tokens=*" %%F in (c:\filelist.txt) do (
  set p=%%~F
  echo xcopy "%%~F" "!p:%source%=%dest%!"
)

Open in new window

That script will only simulate. To actually copy files remove the echo in front of xcopy.
0
 

Author Closing Comment

by:flannk
ID: 34986140
I had to alter slightly but simulate very helpful. thanks
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

816 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

8 Experts available now in Live!

Get 1:1 Help Now