[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

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


0
whargra
Asked:
whargra
  • 4
  • 2
1 Solution
 
WalkaboutTiggerCommented:
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
0
 
whargraAuthor Commented:
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
0
 
WalkaboutTiggerCommented:
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 /^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
WalkaboutTiggerCommented:
You can also add additional logic if you need such as

J:
cd \doc
rem /^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\
     dir/b > j:\filemove.txt
     For /f "tokens=1-4 delims= " %%a in (j:\filemove.txt) do (copy "%%a %%b %%c" "j:\%%a\%%b\%%a %%b %%c")
rem /^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\/^\

I hope this helps

Walkabout
0
 
Seelan NaidooMicrosoft Systems AdminCommented:
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.
0
 
whargraAuthor Commented:
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.
0
 
WalkaboutTiggerCommented:
I'm glad it helped.  The FOR command can be VERY versatile.  

Take care,

Walkabout
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now