Re: How to detect a file has resource fork, or not?
Re: How to detect a file has resource fork, or not?
- Subject: Re: How to detect a file has resource fork, or not?
- From: Axel Luttgens <email@hidden>
- Date: Sat, 10 Apr 2004 15:30:50 +0200
steve harley wrote:
on 16 Mar 2004, at 2:36 AM, Chris Janton wrote:
[...]
[...]
try
do shell script "test -s ~/foo/..namedfork/rsrc"
on error errMsg number errNum
{errMsg, errNum}
end try
"test -s" returns true if a file exists *and* has a size greater than 0
at the shell level that is cleanest.. but in applescript terms it
either returns nothing or it raises an error.. that reflects a
deficiency in do shell script more than anything else
No, "do shell script" is just consistent more than anything else ;-)
In the shell, "test" has a return code of 0 (for true) or 1 (for false);
in both cases, "test" doesn't output anything to stdout nor stderr.
But a non zero return code indicates an error condition, and
AppleScript's "do shell script" command thus raises an error; at the
same time, as nothing got written to stderr, the error message is just a
generic one. [1]
On the other hand, if the test succeeds, there is no error condition and
AppleScript just returns the empty string, as nothing has been written
to stdout.
To make things clearer, consider this one:
try
do shell script "test -s foo"
on error M number N
{M, N}
end try
--> {"Une erreur de type 1 sest produite.", 1}
versus that one:
try
do shell script "echo 'exists'; echo 'does not exist' >&2; test -s foo"
on error M number N
{M, N}
end try
--> {"does not exist", 1}
Now, I agree with you: the question is to know whether it is really a
good idea to let an error condition bubbling up to AppleScript for the
purpose of testing the existence of a file.
After all, when used in the shell, error conditions from commands such
as "test" are generally trapped by other commands (like an "if") or
operators.
So, an approach like this one could be more sensible:
if (do shell script "test -s foo || echo 'no'") = "" then
-- the file exists
else
-- the file does not exist
end if
Hmm... just a two cents.
Axel
[1] The kind of error message that frightens me every time I encounter
it; I'm allways expecting a core dump...
_______________________________________________
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.