DebbieFost
asked on
Need a Script to copy and rename files based on an input file
I have 20,000 documents scattered across multiple folders that I need to have copied to a new location and renamed with a file extension. I would like to have a script that can read an Input file and perform the function accordingly.
Example of original files:
F:\000100\203010\G3.FB
F:\090320\134010\X7.6P
F:\012050\761010\5V.J1
Example of comma delimited input file contents (called C:\Input.csv)
PDF,F:\000100\203010\G3.FB ,Invoice from ABC
DOCX,F:\090320\134010\X7.6 P, Letter to Susie
HTM,F:\012050\761010\5V.J1 ,Bank Rec Report
I would like to have a script that will read the input file and copy & rename the files to the G" drive in the following format:
G:\000100\203010\G3.FB.PDF
G:\090320\134010\X7.6P.DOC X
G:\012050\761010\5V.J1.HTM
We are essentially adding the appropriate file extension to each file (as referenced in the Input.csv file), and copying the document to the G: Drive
Example of original files:
F:\000100\203010\G3.FB
F:\090320\134010\X7.6P
F:\012050\761010\5V.J1
Example of comma delimited input file contents (called C:\Input.csv)
PDF,F:\000100\203010\G3.FB
DOCX,F:\090320\134010\X7.6
HTM,F:\012050\761010\5V.J1
I would like to have a script that will read the input file and copy & rename the files to the G" drive in the following format:
G:\000100\203010\G3.FB.PDF
G:\090320\134010\X7.6P.DOC
G:\012050\761010\5V.J1.HTM
We are essentially adding the appropriate file extension to each file (as referenced in the Input.csv file), and copying the document to the G: Drive
@Bill: Forgot last " on line 5
Cheers,
Rene
Cheers,
Rene
So it should be this then:
@echo off
set DestDrive=G:
set ListFile=C:\input.csv
for /F "usebackq tokens=1,2 delims=," %%A in ("%ListFile%") do (
copy "%%~B" "%DestDrive%%%~pnxB.%%~A"
)
~bp
@Debbie: I don't expect points for my mini-tiny-wanabe-contribut ion, as Bill did all the work!
Cheers,
Rene
Cheers,
Rene
Only thing I'd say is... if the directory structure does not exist on the dest drive already then copy won't create it will it Bill?
It may be worth adding between the for and copy commands:
md "%destdrive%%%~pB"
(I think that's right!)
Steve
It may be worth adding between the for and copy commands:
md "%destdrive%%%~pB"
(I think that's right!)
Steve
Good point Steve, this would address that possibility.
@echo off
set DestDrive=G:
set ListFile=C:\input.csv
for /F "usebackq tokens=1,2 delims=," %%A in ("%ListFile%") do (
if not exist "%DestDrive%%%~pB" md "%DestDrive%%%~pB"
copy "%%~B" "%DestDrive%%%~pnxB.%%~A"
)
~bp
ASKER
Thanks bill (and Rene and Steve) - will give it a whirl today!
ASKER
Ok....thinsk just got a lot simpler.....we no longer need to copy the documents to a new location, we just want to rename them in place!
Can you adjust this script so it just adds the extension to the filename in it's current location? (i.e. F:\,<folder>\,<filename>.< ext>
Can you adjust this script so it just adds the extension to the filename in it's current location? (i.e. F:\,<folder>\,<filename>.<
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
~bp