2 votos

¿Por qué "si existe" falla con un falso positivo?

El archivo, "Test.file" en el código de abajo no existe, pero el script devuelve true. ¿Por qué? ¿Qué estoy haciendo mal?

set thePath to (path to application support folder from user domain)

if exists thePath & "Test.file" then
display dialog "The file was found!" buttons {"OK"} default button 1
else
display dialog "The was file wasn't found." buttons {"OK"} default button 1
end if

2voto

adayzdone Puntos 1258

Es necesario hacer referencia a un archivo para que la prueba funcione correctamente.

set thePath to path to application support folder from user domain
tell application "System Events" to exists file ((thePath as text) & "Test.file")

Con el condicional:

set thePath to path to application support folder from user domain
tell application "System Events" to exists file ((thePath as text) & "Test.file")
if the result then
    display dialog "The file was found!" buttons {"OK"} default button 1
else
    display dialog "The was file wasn't found." buttons {"OK"} default button 1
end if

AppleAyuda.com

AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X