• 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: Gnarlodious <email@hidden>
  • Date: Mon, 13 Feb 2006 11:15:49 -0700
  • Thread-topic: File exists on a posix path

Title: Re: File exists on a posix path
This appears to be the minimum functional usage:

set filePath to "/Users/"

set cmd to "test -e '" & filePath & "';echo $?"
not ((do shell script cmd) as integer) as boolean

Takes a POSIX path only. Operates on folders AND files, so that is pretty cool.

-- Gnarlie


Entity Bastiaan Boertien spoke thus:

maybe this ?

on checkIfFileExists(thefile)
if character 1 of thefile = "/" then
return
(((do shell script ("if test -e '" & thefile & "' ; then echo 1 ; else echo 0 ; fi" as string)) as integer) as boolean)
else
return
(((do shell script ("if test -e '" & POSIX path of thefile & "' ; then echo 1 ; else echo 0 ; fi" as string)) as integer) as boolean)
end if
end
checkIfFileExists

The input needs to be a full path of the file. It can be an macintish path or an posix path


Op 10-feb-2006, om 23:37 heeft Christopher Nebel het volgende geschreven:

On Feb 10, 2006, at 11:45 AM, Gnarlodious wrote:

 
I think what you mean is this:

do shell script "ls ~/testfile"

Unfortunately if testfile does not exists then Applescript errors. I believe
this situation started in 10.4, because before then it returned a nul
string. But regardless, you now need to wrap it in a try statement:

try
    do shell script "ls ~/testfile"
on error
    return ""
end try

or some such gyration. I wish Apple would fix it, but it won't happen since
I didn't complain about it.
 

Not to mention the fact that ls's exit status is defined by POSIX.  Take it up with them if you like, but I don't expect you'll get very far.  Incidentally, it would be better to ask the question you actually wanted to ask, rather than relying on a side effect.  In this case, assuming you're committed to using the shell, that would be to use test(1).


--Chris Nebel
AppleScript and Automator Engineering

_______________________________________________
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

 _______________________________________________
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: Bastiaan Boertien <email@hidden>)

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