flannk
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\direc tory2\1DC\ 0000AD30.0 17
\\server1\directory1\direc tory2\1DE\ 0000AD32.0 01
\\server1\directory1\direc tory2\1DE\ 0000AD32.0 02
\\server1\directory1\direc tory2\1E2\ 0000AD36.0 01
\\server1\directory1\direc tory2\1E2\ 0000AD36.0 02
\\server1\directory1\direc tory2\1E3\ 0000AD37.0 01
\\server1\directory1\direc tory2\1E4\ 0000AD38.0 01
\\server1\directory1\direc tory2\1E5\ 0000AD39.0 01
\\server1\directory1\direc tory2\1E6\ 0000AD3A.0 01
Destination:
\\server2\diffdirectory1\d iffdirecto ry2\diffdi rectory3\d iffdirecto ry4\1DC\00 00AD30.017
\\server2\diffdirectory1\d iffdirecto ry2\diffdi rectory3\d iffdirecto ry4\1DE\00 00AD32.001
\\server2\diffdirectory1\d iffdirecto ry2\diffdi rectory3\d iffdirecto ry4\1DE\00 00AD32.002
\\\server2\diffdirectory1\ diffdirect ory2\diffd irectory3\ diffdirect ory4\1E2\0 000AD36.00 1
\\server2\diffdirectory1\d iffdirecto ry2\diffdi rectory3\d iffdirecto ry4\1E2\00 00AD36.002
\\\server2\diffdirectory1\ diffdirect ory2\diffd irectory3\ diffdirect ory4\1E3\0 000AD37.00 1
\\server2\diffdirectory1\d iffdirecto ry2\diffdi rectory3\d iffdirecto ry4\1E4\00 00AD38.001
\\\server2\diffdirectory1\ diffdirect ory2\diffd irectory3\ diffdirect ory4\1E5\0 000AD39.00 1
\\server2\diffdirectory1\d iffdirecto ry2\diffdi rectory3\d iffdirecto ry4\1E6\00 00AD3A.001
Any assistance will be most greatly appreciated. Cheers
(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\direc
\\server1\directory1\direc
\\server1\directory1\direc
\\server1\directory1\direc
\\server1\directory1\direc
\\server1\directory1\direc
\\server1\directory1\direc
\\server1\directory1\direc
\\server1\directory1\direc
Destination:
\\server2\diffdirectory1\d
\\server2\diffdirectory1\d
\\server2\diffdirectory1\d
\\\server2\diffdirectory1\
\\server2\diffdirectory1\d
\\\server2\diffdirectory1\
\\server2\diffdirectory1\d
\\\server2\diffdirectory1\
\\server2\diffdirectory1\d
Any assistance will be most greatly appreciated. Cheers
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?
MD is Command for create Directory
MD \\server2\diffdirectory1\d iffdirecto ry2\diffdi rectory3\d iffdirecto ry4\1DC
MD \\server2\diffdirectory1\d
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"
)
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.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had to alter slightly but simulate very helpful. thanks
try this. You can leave out the domain part if you don't use it.
Open in new window