• 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: Finder's "exists" command ignores leading zero's in filename
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finder's "exists" command ignores leading zero's in filename


  • Subject: Re: Finder's "exists" command ignores leading zero's in filename
  • From: Stan Cleveland <email@hidden>
  • Date: Fri, 23 May 2014 18:55:01 -0700

On May 23, 2014, at 4:28 PM, Shane Stanley wrote:

> Are you sure the speed up is not due to the different time it takes to resolve "file x of folder y of desktop" versus "file z"?

Hi Shane,

Here are two more variations. Both indicate that you're right about file references taking longer to resolve.

The first skips having the Finder get and store the file name in a variable, and just uses a string instead to test the name. It's nearly all strings and is the fastest version yet:

    -- takes 0.9 seconds
    set filePath to "MacHD:Users:stanc:Desktop:Test:Test_00001.txt"
    tell application "Finder"
        repeat 1000 times
            tell file filePath to set fileExists to ((it exists) and (its name begins with "Test_00001.txt"))
        end repeat
    end tell

The second variation has the Finder store a file reference in a variable for testing existence, but also uses a string to test the file name. This is the slowest by far:

    -- takes 13.50 seconds
    tell application "Finder"
        set fileRef to file "Test_00001.txt" of folder "Test" of desktop
        repeat 1000 times
            tell fileRef to set fileExists to ((it exists) and (its name begins with "Test_00001.txt"))
        end repeat
    end tell

Apparently, the "tell fileRef" in every iteration of the loop forces the Finder to re-resolve the reference stored in the variable.

Stan C.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


  • Follow-Ups:
    • Re: Finder's "exists" command ignores leading zero's in filename
      • From: Shane Stanley <email@hidden>
References: 
 >Re: Finder's "exists" command ignores leading zero's in filename (From: Nigel Garvey <email@hidden>)
 >Re: Finder's "exists" command ignores leading zero's in filename (From: Stan Cleveland <email@hidden>)
 >Re: Finder's "exists" command ignores leading zero's in filename (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Finder's "exists" command ignores leading zero's in filename
  • Next by Date: Re: Finder's "exists" command ignores leading zero's in filename
  • Previous by thread: Re: Finder's "exists" command ignores leading zero's in filename
  • Next by thread: Re: Finder's "exists" command ignores leading zero's in filename
  • Index(es):
    • Date
    • Thread