Re: delete first 3 characters in a file name
Re: delete first 3 characters in a file name
- Subject: Re: delete first 3 characters in a file name
- From: Andrew Oliver <email@hidden>
- Date: Thu, 09 Dec 2004 09:50:10 -0800
On 12/9/04 8:40 AM, "Jan-Bultereys" <email@hidden> wrote:
> Does anybody know how to delete the first 3 characters of a variable file
> name?
>
> meaning:
> select a couple of files in a folder all starting with 001_test, 103_test2,
> 203_test3 for example
> then rename them to test1, test2, test3.....
>
> any input would be appreciated
You can manipulate any text object using the standard format:
set theFilename to "001_test1"
set newFilename to (characters 5 through -1 of theFilename) as text
The -1 indicates the last character (or first character from the end) of the
text object.
So, a generalized hander for your script (untested, with no error checking)
might look like:
tell application "Finder"
set theFile to (choose file)
set name of theFile to (characters 5 through -1 of (name of theFile)) as
text
end tell
There are obvious flaws in this script - there's no check that it's the
format of the filename you indicate, it'll just chop off the first 4
characters, and it will fail if the filename is less than 4 characters, but
you get the idea, I'm sure.
Andrew
:)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden