• 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: Shane Stanley <email@hidden>
  • Date: Fri, 23 May 2014 09:47:14 +1000

On 23 May 2014, at 1:36 am, Thomas Fischer <email@hidden> wrote:

Le 22/05/2014 à 16:01, Bert Groeneveld <email@hidden> a écrit :

set path_to_desktop to path to desktop folder
set my_img to path_to_desktop & "2028.jpg" as string
tell application "Finder"
set file_found to exists my_img
end tell

When I change the name of the file on the desktop from "2028.jpg" into "002028.jpg" I hope to receive false as the result from above script, but the result is still true. It seems that the leading zero's are ignored. How can I fix that?

Thanks in advance for any help,
Bert.

Perfectly normal !

Your code is not checking the existence of a file but the existence of the string my_img.

Right.

I have to disagree.
It looks for the file but for the Finder these files seem to be identical. 
I tested with

set path_to_desktop to path to desktop folder
set my_img to path_to_desktop & "000234.txt" as string
tell application "Finder"
set myRef to a reference to file my_img
set file_found to exists file my_img
try
open myRef
end try
end tell

Your code inserts the word "file" -- that's precisely what Yvan was suggesting.

I'm not sure what your point is in using "a reference to" -- all it does is complicate things.

Also, the first two lines are dangerous -- your result depends on the value of text item delimiters because you're creating list of an alias and a string, and then coercing that to a string. Much better (as in safer/quicker/more efficient) to use:

 set path_to_desktop to path to desktop folder as text
 set my_img to path_to_desktop & "000234.txt"

The Finder dictionary is clear: commands like exists take a reference to an object. A string is never a reference to an object.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

References: 
 >Finder's "exists" command ignores leading zero's in filename (From: Bert Groeneveld <email@hidden>)
 >Re: Finder's "exists" command ignores leading zero's in filename (From: "koenig.yvan" <email@hidden>)
 >Re: Finder's "exists" command ignores leading zero's in filename (From: Thomas Fischer <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