Re: Read Text File to Rename Images - Please help! [A bit OT
Re: Read Text File to Rename Images - Please help! [A bit OT
- Subject: Re: Read Text File to Rename Images - Please help! [A bit OT
- From: email@hidden
- Date: Thu, 6 Sep 2001 00:34:05 -0400
On: Thu, 06 Sep 2001 11:56:47 +0930,
Paul McCann <email@hidden> suggested,
>
Ray asked...
>
>
> I have just learned tonight I will have to rename *all* of the original web
>
> files on our server, from our current part number (SKU) to another number
>
> (EBU #) for our new e-commerce system. Of this, there are close to 3,269
>
> give or take a few jpgs. Some will have to be re-shot.
>
>
Sounds like one of those horrible moments when your whole body experiences
>
that "sinking feeling". I'm going to risk the language police coming down on
>
me like a ton of bricks (yep, I know this is an applescript forum), but what
>
the heck: Applescript is great for some jobs, but I think this sort of thing
>
is best done by another tool. If you have Macperl installed --or either (i)
>
you are not averse to spending five minutes installing it, or (ii) you are
>
sufficiently desperate!!-- I think the following script will do pretty much
>
exactly what you've specified.
>
Obviously the same thing could be done in applescript, but I bet it's
>
truckloads quicker in macperl.
I have an AppleScript that does the same thing. It could be slower, for two
reasons:
(1) I'm using the renameFiles command from Jon's Commands, and the AppleEvent
sending time will take time. Still, its faster than telling the Finder. But I
imagine that perl does an internal call to its 'rename' function, which should
be faster.
(2) I provide a status window, and rendering to this window requires an
inter-process AppleEvent and a task switch. That probably slows things down
more than anything else.
Also, if you are comparing the two scripts, note that the perl script makes a
copy of the file and renames that; the AppleScript merely renames them. Also,
the perl script gets a list of the whole directory, and then looks for files
which have new names, while the AppleScript just takes the list and tries to do
each renaming stated, and trapping for the error that happens if the file
doesn't exist. If the renaming list is accurate, the method in the AppleScript
would be a hair faster, but if any significant number of files didn't exist, the
balance would shift to the directory-reading approach.
>
I've written the thing with a view to
>
understandability instead of conciseness/cuteness in the hope of providing
>
an example of how perl scripts needn't be unreadable. With any luck some
>
people might find it useful in other situations. It's a bit crude in that it
>
makes two independent mappings; one of the old name to the new names of the
>
files, and another that's used in the duplication of the files. Some memory
>
could definitely be saved there, but it's not going to be a big issue for
>
circa 3000 files.
Hats off to your good writing.
>
Obviously you'll need to change the hard-coded locations of the
>
"name_maps.txt" file and the "images" folder. If you have any problems with
>
it (or can't get it to run properly, or don't see what's being done) feel
>
free to contact me off-list.
Now, here is where AppleScript made things easy. I've got hard-coded properties
for these two parameters, too, but the user can modify them by dropping a file
or a folder on the script icon. (I guess if you write AppleScript, you keep
more of the user-centric Mac attitude.) This is easy because making a droplet
is built right in to AppleScript, and because AppleScript has persistent
properties.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden