• 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: Nigel Garvey <email@hidden>
  • Date: Fri, 10 Dec 2004 18:14:43 +0000

Michelle Steiner wrote on Thu, 9 Dec 2004 17:10:41 -0700:

>On Dec 9, 2004, at 10:32 AM, Bill White wrote:
>
>>         set newName to characters 5 thru -1 of oldName as string

  set newName to text 5 thru -1 of oldName

... is to be preferred. It cuts out the 'character list' stage and isn't
affected by the state of the TIDs.

>By using txt item delimiters set to "_", the number of characters to be
>stripped is not an issue, nor is the number of characters to be
>retained.  It is a more general solution, and makes only the assumption
>that there is an underscore in the file name, and that only those
>characters after the underscore are to be retained.

... and that there's only one underscore in the name. It's also fast, of
course. But that's not relevant if the file access isn't as efficient as
it could be. Rather than getting all the files in the folder and then
getting each one's name individually, you can simply get the names all in
one go:

  set foo to (choose folder)
  set underscore to "_"
  set astid to Applescript's text item delimiters
  set AppleScript's text item delimiters to underscore
  try -- error if no files in the folder
    tell application "Finder" to set oldNames to name of foo's files
    considering case
      repeat with i from 1 to (count oldNames)
        set thisName to item i of oldNames
        if (thisName contains underscore) then
          set newName to text from text item 2 to -1 of thisName
          tell application "Finder" to set name of file thisName of foo
to newName
        end if
      end repeat
    end considering
  end try

>--
>Windows was always a mystery to me; the biggest mystery being "Why does
>anyone want to use this?"

:-)

The Jean-Claude van Damme file "Street Fighter" was shown on our Channel
5 a few days ago. During the punch-up at the end, one of the megalomaniac
villain's computer programmers cried out: "Aaaah! I should have stayed at
Microsoft!"

NG
 _______________________________________________
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

  • Prev by Date: Re: truncate the hostname of local computer
  • Next by Date: Activate a Window in Safari
  • Previous by thread: RE: delete first 3 characters in a file name
  • Next by thread: Preferences (user defaults) in Applescript Studio
  • Index(es):
    • Date
    • Thread