Link to home
Start Free TrialLog in
Avatar of flannk
flannkFlag for Australia

asked on

copy multiple files from multiple subdirectories to different location

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

Avatar of ceesios
ceesios

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

Avatar of flannk

ASKER

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?
Avatar of Kalpesh Chhatrala
MD is Command for create Directory

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

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

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.
Avatar of flannk

ASKER

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.
The xcopy command from Draxonic should fix that, just replace copy with xcopy.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of flannk

ASKER

I had to alter slightly but simulate very helpful. thanks