Re: Finder's "exists" command ignores leading zero's in filename
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.
|
_______________________________________________
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