[testing if file exists ... again]

Hi all,

I’m new to apple script, and I have a problem that i can’t solve : I’d like to test the existence of a file / folder, but it does not work

I’ve found within this forum several solutions to my problem, but none have fixed my problem


set foo to choose file
try
	alias foo
on error
	display dialog "error"
end try


==> display “error”


set foo to choose file

if (exists file foo) then
	display dialog "it exists"
else
	display dialog "are you going crazy ???"
end if

Impossible to transforme file (alias “Users:weel31:Desktop:toto.txt”) in type reference

any help would be very welcome.

set foo to choose file
try
   alias foo
on error
   display dialog "error"
end try

The “choose file” command returns an alias. So you will never ever get a warning. Because if you were able to choose the file then it exists. Quite obvious, isn’t it.:P;)

But maybe you could show us the code of the script where you want to use the existance test. In the example above the check is quite useless.

yes it is quiet obvious, but in fact,
I have an editable text field : user can
either type in the path to the file,
or to select the file using a ‘browse’ button’.

that’s why I want to check file existence , for the first case.

but anyway, I fix the problem I encountered using POSIX (from Applescript to Unix and vice versa)
http://www.satimage.fr/software/en/file_paths.html

thanks for help :wink: