• 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: POSIX paths query explained better
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: POSIX paths query explained better


  • Subject: Re: POSIX paths query explained better
  • From: Christopher Nebel <email@hidden>
  • Date: Wed, 8 Oct 2003 09:56:12 -0700

On Oct 8, 2003, at 9:03 AM, Steve Thompson wrote:

After thinking about this, I now know why it doesn't work but I still can't find out how to work around it. Obviously (I think) the Finder doesn't understand POSIX paths.

Bingo.

So, what I need is a way of doing "exists" on a volume that isn't mounted in the Finder. Can someone point me in the right direction? I suppose I could do a 'ls' of the directory as a shell script and see if the file name is in the resulting text, but is there a tidier way to do it?

This is what test(1), aka "[", is for. It lets you test all sorts of things, among them whether or not a file exists. It will throw an error if the condition is false, so you could do something like this:

try
do shell script "test -f " & quoted_path
on error
"doesn't exist!"
end

Alternatively, trap the error in the shell script itself:

do shell script "test -f " & quoted_path & " && echo yes || echo no"
if the result is "yes" then "It exists!"

(You need the "|| echo no" part even if you don't test for "no", because that suppresses the error, so you don't need a "try" block in your script.)

On Oct 8, 2003, at 9:08 AM, Patrick Mast wrote:

<POSIX path of> will already check if the file exists. thats why you will get an error message if you want to make the HFS formated path of a file that does not exist to an POSIX formated path.

It does no such thing. Try it:

set f to "foo:bar:baz"
POSIX path of file f --> "/foo/bar/baz"

Needless to say, there is no such file on my system. Incidentally, the fact that the following works is a bug:

set f to "foo:bar:baz"
POSIX path of f --> "/foo/bar/baz"

Notice that f is a string, not a file reference. This wasn't supposed to work, but does, and will never be fixed in a dot update because obviously people are relying on it now, but try not to get in the habit. Say it with me, people: strings are not file references.


--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: POSIX paths query explained better
      • From: Steve Thompson <email@hidden>
References: 
 >POSIX paths query explained better (From: Steve Thompson <email@hidden>)

  • Prev by Date: Re: POSIX paths query explained better
  • Next by Date: Re: POSIX paths query explained better
  • Previous by thread: Re: POSIX paths query explained better
  • Next by thread: Re: POSIX paths query explained better
  • Index(es):
    • Date
    • Thread