• 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: File exists on a posix path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File exists on a posix path


  • Subject: Re: File exists on a posix path
  • From: Paul Berkowitz <email@hidden>
  • Date: Fri, 10 Feb 2006 12:06:43 -0800
  • Thread-topic: File exists on a posix path

Title: Re: File exists on a posix path
No, Adam. At least it's not doing what you think it is. For example, this also has a 'true' result:

set y to POSIX path of quoted form of "/user/sbin/boop"
exists y --> true


whereas there is no such file. That's because you're just testing for a string, not an actual file. (You just sent a new message to the list where you've noticed that.)
And if you check the value of y:

y
-->
/':user:sbin:boop'


Not too useful...

Evidently 'exists' is now part of the AppleScript language - I think it used to be just part of the Standard Suite, and had to be implemented by the Finder (or other application) syntax. It's odd that it not only compiles but gives a (spurious) result. But it will tell you that any string exists.

An error in Charles's code was that he set the variable a to a file, and then stuck 'file' in front of the variable, That will always error - it's 'file file y' which isn't anything.

Mark's method is best, but could be tightened up:

set y to "/usr/sbin/installer"
try
   set a to POSIX file y as alias
   display dialog " already exists"
on error
   display dialog "doesn't exist"
end try


Or if you prefer to use 'exists' you have to do it in the Finder:

set y to "/usr/sbin/installer"
set a to POSIX file y
tell application "Finder"
    activate
   if exists a then
       display dialog " already exists"
    else
       display dialog "doesn't exist"
    end if
end
tell


This time you're using the Finder's 'exist' to check for a file. (At least in 10.4, it does equate the AppleScript 'file' in line 2 to an actual object equivalent to a Finder file. It may be that in earlier versions you might have to explicitly set a to POSIX file y as Unicode text, and then in the Finder block check for 'exists file a'.) You'll note that a once again is just a string.

In both these scripts the result is meaningful: if you substitute "boop" for "installer" it will tell you that it "doesn't exist".

--


Paul Berkowitz



From: Adam Bell <email@hidden>
Date: Fri, 10 Feb 2006 15:38:30 -0400
To: Applescript <email@hidden>
Subject: Re: File exists on a posix path

set y to POSIX path of quoted form of "/user/sbin/installer"
exists y --> true, in my case

On 2/10/06, Charles E. Heizer < email@hidden <mailto:email@hidden> > wrote:
Hello,
I really don't use Applescript very offten but I have a need right
now. I would like to know how to do a file exists on a posix file

example:

set y to "/usr/sbin/installer"
set a to POSIX file y
if (the file a exists) then
        display dialog " already exists"
end if


Thanks!
- charles


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      ( email@hidden <mailto:email@hidden> )
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



--
Some minds remain open long enough for a truth to both enter and leave without processing.

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

References: 
 >Re: File exists on a posix path (From: Adam Bell <email@hidden>)

  • Prev by Date: Re: File exists on a posix path
  • Next by Date: Dealing with Sliders...
  • Previous by thread: Re: File exists on a posix path
  • Next by thread: Re: File exists on a posix path
  • Index(es):
    • Date
    • Thread