Re: File exists on a posix path
Re: File exists on a posix path
- Subject: Re: File exists on a posix path
- From: Christopher Nebel <email@hidden>
- Date: Tue, 14 Feb 2006 09:14:54 -0800
On Feb 13, 2006, at 7:08 AM, Adam Bell wrote:
In 10.4.4 at least, I had to modify the first shell script as
follows to deal with folder names or file names with spaces in them:
return (((do shell script ("if test -e " & "'" & thefile &
"'" & " ; then echo 1 ; else echo 0 ; fi" as string)) as integer)
as boolean)
Note: I just moved the single quotes which wouldn't compile inside
the first quoted string. Using 'quoted form of' might be better.
It unquestionably is better, because it will deal correctly with
paths that have single quotes in them, unlike yours. Never attempt
to do your own quoting; I guarantee your code will fail for some cases.
To answer Gnarlie's question, test(1) doesn't return anything, in the
sense that it doesn't generate any output. Its success or failure is
signaled by its exit status, which means to test it in shell you need
either an "if" block or its moral equivalent "&&" and "||". For
example, these two are equivalent:
if test -e $thefile ; then echo 1 ; else echo 0 ; fi
if test -e $thefile && echo 1 || echo 0
Of course, Gnarlie's observation that you can "echo $?" instead is
even shorter.
--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