clickin
02-16-2005, 09:25 AM
I need a script like a mail merge! I want to rename my files to the names of the students. I have a excel spread sheet with all the names and the file names. I need a script to rename the camera file name to the person's name.jpg. I hope that was clear. Does anyone have any ideas? I am new to scripts. I do understand that this would be a VB script to be able to open up an excel document. If anyone has ideas for me on were to start let me know. thanks
Hi there clickin, welcome to RetouchPRO.
It's a shame that I won't have time to try this for a couple of days, but what you want is pretty easy to do.
Just a note though. Although VB isn't off bounds by any means, most people are more used to writing Photoshop scripts in javascript (JS). In practice the difference would be that you'd just have to export the excel data to a text file so JS can get a hold of it.
If nobody cracks this in the mean time, I'll have a go this weekend.
Rô
MBChamberlain
02-16-2005, 10:40 AM
You could just convert your excel file into a batch file to replace...
1) You need a program that allows regular expressions...if you don't have one there is a really good free one called vim (you can download it here (http://www.vim.org))
2) Export your excel file as a delimeted file using a character not in your file (like the semicolon)
3) Open it in the program with regular expression replacement
4) Perform a regular expression find replace to create the commands to rename you files
5) Change the file extension to "bat"
6) Run the script
If you are using vim, you would navigate to the folder you saved your file and type:
vim <filename>
vim has no gui, so you have to type all the commands...
if your format is <filename>;<Name> type the following string pattern:
: the colon gets you a prompt
%s/\([^;]*\);\([^;]*\)/rename "\1" "\2.jpg"/
where jpg is your file type
\( \) denotes it as a reference
[^;] says to take any character but a ";"
* means accept any number of the previous set, meaning any group of characters that do not contain a ";"
the \1 and \2 refer to your previous references.
this will change the line:
file.jpg;Doe, John
to
rename "file.jpg" "Doe, John.jpg"
if you let me know how the file is layed out I can get you the exact search string.
then finally you would type ":wq" to save and close the file.
Regular expressions are very powerful, and it really will save you a lot of time in a lot of tasks if you get to know them well.
Hope that helps,
Michael
clickin
02-16-2005, 10:50 AM
Java or VB it doesn't matter. I was hoping to write it in Java ... but thought that the file thing would make it easier in VB. If you have a chance, I would appreciate any help.
thanks
xbytor
02-17-2005, 06:23 PM
1) Export the file as a csv (comma separated values). This is done manually from Excel.
2) Write a JS script that reads the csv a line at a time.
3) Break each line into its component parts. JS does actually have very good regular expression support, but a simple String.split(",") call may be sufficient.
4) Use the JS File APIs to rename, copy, or do whatever it is you need to do with the files.
There are other ways of doing this, but you have Photoshop which means you have JS available. Personally, this is the kind of problem that I would use perl or bash to solve.
ciao,
-X