• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
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


  • 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

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

  • Prev by Date: Re: Unwinding the containment hierarchy of a reference
  • Next by Date: Re: delete first 3 characters in a file name
  • Previous by thread: Re: delete first 3 characters in a file name
  • Next by thread: Re: delete first 3 characters in a file name
  • Index(es):
    • Date
    • Thread