I would appreciate any help. I have several applescripts that I use to perform many useful functions. I have one that I use that renames a file(s) by taking off a suffix on a filename. For instance, I can drop several files on the script where it will delete the “.jpg” extension from the filename. What I am having trouble with now is, I have thousands of files that are named something similar to “901366_123.pdf”. What I want the script to do is strip off the prefix of the file “901366” and rename it to 123.pdf.
The “123” digits will change from file to file. I can’t seem to get it to work properly.
I am using OS X 10.3.3. Any help would be much appreciated.
This might work but I suggest that you add error handling to deal with issues that might arise (for example, what should the script do if the truncated name is already in use?).
on open files_
repeat with file_ in files_
tell application "Finder" to set old_name to name of file_
set offset_ to offset of "_" in old_name
try
tell application "Finder" to set name of file_ to text (offset_ + 1) thru end of old_name
on error e
display dialog e
end try
end repeat
end open
With that said, I highly recommend Name those Files!, which is developed (new features and improvements are incoporated on a regular basis) by Jonathan Nathan, a frequent contributor to this forum.