• 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: I've changed the name of a file - now how do I get at path to the new name?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I've changed the name of a file - now how do I get at path to the new name?


  • Subject: Re: I've changed the name of a file - now how do I get at path to the new name?
  • From: Shane Stanley <email@hidden>
  • Date: Fri, 03 Nov 2000 21:32:37 +1100

On 3/11/00 9:02 PM +1000, Richard 23, email@hidden, wrote:

> Here's a couple of handlers (and a property) I rarely do without:

I have to ask: Why? I mean, I'm happy enough to use something that makes my
head hurt if there's some gain, but here I'm lost. (I'm no programmer.)

Being fairly literal about these things, I would write something like:

on GetName(filePath)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theName to text item -1 of filePath
if filePath ends with ":" then
set theName to theName & ":"
end if
set AppleScript's text item delimiters to oldDelims
return theName
end GetName

I know I can optimise it a bit, but I can see clearly what's happening, and
I suspect any gains would be relatively minor. But instead, you offer:

property |t/d| : a reference to AppleScript's text item delimiters

on GetName(filePath)
set {|t/d|'s contents} to {":"}
set filePath to filePath as string
set {|t/d|'s contents} to {"", filePath's text item |?|(filePath ends with
":", -2, -1)}
result's end
end GetName

on |?|(|boolean|, ifTrue, ifFalse)
log |boolean|
if |boolean| = true or |boolean| is not equal to false then
ifTrue
else
ifFalse
end if
end |?|

OK, so let's run them both with the following:

set time1 to the ticks
repeat 1000 times
GetName("mac:Here:there:")
end repeat
set time2 to the ticks
display dialog ("That took " & ((time2 - time1)) as text) & " ticks."

The results I get are of the order of 24 ticks for the first way, and at
least nine times that for the other. So what am I missing? Am I overlooking
some hidden smileys?


--
Shane Stanley, email@hidden


  • Follow-Ups:
    • Re: I've changed the name of a file - now how do I get at path to the new name?
      • From: Shane Stanley <email@hidden>
References: 
 >Re: I've changed the name of a file - now how do I get at path to the new name? (From: Richard 23 <email@hidden>)

  • Prev by Date: Re: I've changed the name of a file - now how do I get at path to the new name?
  • Next by Date: Re: I've changed the name of a file - now how do I get at path to the new name?
  • Previous by thread: Re: I've changed the name of a file - now how do I get at path to the new name?
  • Next by thread: Re: I've changed the name of a file - now how do I get at path to the new name?
  • Index(es):
    • Date
    • Thread