AppleScript - rename files

This is a discussion on AppleScript - rename files within the C Programming forums, part of the General Programming Boards category; Hi all,
Just lookin for some C script to rename files in a directory while iterating thru files 1 by ...

AppleScript - rename files

Hi all,

Just lookin for some C script to rename files in a directory while iterating thru files 1 by 1,

been searchin for some time now but cant seem to get code together.
Apple has a builtin scripting which is called applescript that does this but its not efficient, though the goal is almost the same...

> Apple has a builtin scripting which is called applescript that does this but its not efficient,
Writing it in C isn't going to make it vastly quicker. Nearly all the work is being done outside the code you write, so whether you write it in Applescript or C won't make that much of a difference.

Like what matsp posted, a script takes 30 seconds to write (and then you throw it away probably), whereas a C program might take you all day if you're not already adept at programming in C (this thread is already 3 hrs old, and your program isn't finished yet).

being at work i havent really had a chance to run any code, but still appreciate the help
speed is not what i m really interested in as Apples automator changes the names of 100 files in a folder in about say 10 seconds or even less never calculated...

I have been lookin to write the code for this task in any language that i can...
1 reason C appealed more than the others is i can run C in apples terminal where as for languages like php or java i need to install additional software to compile and run...

shell script looks quite interesting and might be good if i can hack some code like that...

What is the actual renaming you are doing? Are you doing this on a regular basis? What are the original names, and what are the new names (you don't need to give details, but say for example you are renaming IMG_nnnn.JPG to Portrait_Lisa_nn.jpg would give us some idea of what you are actually trying to do. Getting a "bigger picture" often helps in the recommendation of the right solutions.

Ok. Like Salem, I believe the majority of the time consumed by something like this is the time it takes to ACTUALLY rewrite the directory entry of the file. So it's unlikely that the AppleScript is taking much of the time, compared to the actual rename operation itself. I could of course be wrong.

now that i see the struct and the tabel i understand what is meant by the time spent outside the code

i was planning to iterate the directory without being have to hard code the file name...

Yes, of course, and you can do that, but it would require a lot of string parsing and other stuff. So instead of spending many hours coming up with the code to convert one filename into another filename with the string parsing and string generation, use simple table to estimate how quickly it can be done - if this proves either side of the argument (AppleScript is slow vs. the actual task of renaming the file is the expensive part), then you know which way to go, and where to spend your time.

> i was planning to iterate the directory without being have to hard code the file name.
Yes, which is yet more time spent outside the program, seeking all over those extremely slow hard disks (in program time terms).