Link to home
Start Free TrialLog in
Avatar of whargra
whargra

asked on

Copy specific file to specific folder

I have a folder that has numerous files in it that I need to copy a specific file to a specific folder. Does anyone have a script that can do this?

The file names vary but do all start similar. The folders that I am moving the files to have already been created.

J:\docs\BR 312 sometexthere.doc              ---> copy to this folder ---> J:\BR\312\BR 312 sometexthere.doc
J:\docs\BR 1121 somemoretexthere.doc     ---> copy to this folder ---> J:\BR\1121\BR 1121 somemoretexthere.doc
J:\docs\BR 52 othertextishere.doc              ---> copy to this folder ---> J:\BR\52\BR 52 othertextishere.doc


Avatar of Darrell Porter
Darrell Porter
Flag of United States of America image

Is the format of the files always going to be

xx yyyy zzzzzzzzzzzzz.ext

Where

xx is a two-letter designator
yyyy is a 2- to 4-digit number
zzzzzzzzzzzzz is a detailed file description
ext is any extension

?

I will try to have a script for you by end of day based on this info
Avatar of whargra
whargra

ASKER

Yes,
xx is BR and will not vary
yyyy is 2 to 4 digits
zzzzzzzzzzzzzzzzz this will vary in size

and the extension will always be a .doc as they are Word files

Thanks
Here is the script:

rem /^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\
      dir/b > filemove.txt
      For /f "tokens=1-4 delims= " %%a in (filemove.txt) do (copy "%%a %%b %%c" "\%%a\%%b\%%a %%b %%c")
rem /^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\
ASKER CERTIFIED SOLUTION
Avatar of Darrell Porter
Darrell Porter
Flag of United States of America 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
Try using a utility call robocopy (Robust File Copy utility) part of the Win2k3 res kit..

You can download it here

http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en

For your scenario, this would be the syntax..

J:\docs\BR 312 sometexthere.doc              ---> copy to this folder ---> J:\BR\312\BR 312 sometexthere.doc
J:\docs\BR 1121 somemoretexthere.doc     ---> copy to this folder ---> J:\BR\1121\BR 1121 somemoretexthere.doc
J:\docs\BR 52 othertextishere.doc              ---> copy to this folder ---> J:\BR\52\BR 52 othertextishere.doc

Make sure robocopy exists in the docs folder..

from command prompt, or scheduled task

robocopy "J:\docs\BR 312 sometexthere.doc" "J:\BR\312\BR 312 sometexthere.doc" /MIR /SEC /LOG+:J:\BR312.txt /TEE
robocopy "J:\docs\BR 1121 sometexthere.doc" "J:\BR\1121\BR 1121 sometexthere.doc" /MIR /SEC /LOG+:J:\BR1121.txt /TEE
robocopy "J:\docs\BR 52 sometexthere.doc" "J:\BR\52\BR 52 sometexthere.doc" /MIR /SEC /LOG+:J:\BR52.txt /TEE

/MIR = mirrors the structure
/SEC = copy security settings of file
/LOG+: = location of log file, which appends subsequent entries
/TEE = give a verbose output, you can turn it off as desired.

There are many other switches and combinations that you can use. Have a look at the doc that comes with robocopy.
Avatar of whargra

ASKER

Thanks Walkabout, a little tweaking and it works very well. For sure beats having to manualy do this!!!

SeanUK777, I'll take a look at that if I can get the server folks to install it.
I'm glad it helped.  The FOR command can be VERY versatile.  

Take care,

Walkabout