Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: delete first 3 characters in a file name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: delete first 3 characters in a file name

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
 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.


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

 >delete first 3 characters in a file name (From: "Jan-Bultereys" <email@hidden>)

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.