Re: How to detect if a file exists
Re: How to detect if a file exists
- Subject: Re: How to detect if a file exists
- From: "Stockly, Ed" <email@hidden>
- Date: Fri, 17 Jul 2009 16:29:09 -0700
- Thread-topic: How to detect if a file exists
Title: Re: How to detect if a file exists
On 07/17/09 4:10 PM, "Andrew P" wrote:
>>>This is really, really simple.
Not so much. There are actually several things happening here.
>>>I'm using an exists command to tell me if a document exists, and for some reason it wont work. Here's the script:
>>>if "/Users/Andrew/Desktop/Stencil.doc" exists then (display dialog "Hello world")
In your script AppleScript does not know that the string "/Users/Andrew/Desktop/Stencil.doc" is a reference to a file. You’re essentially asking if the string itself exists and, since it’s right there in the script, it does exist so the condition is true and the dialog displays.
What you want to do is enclose the command inside a finder tell, and indicate it’s a file reference, but AppleScript uses colons to delimit directories, so you’ll either want to coerce your path to an alias or use this format for your file reference.
tell application "Finder"
if file "MacOSX:Users:ThreePigs.txt" exists then (display dialog "Hello world")
end tell
HTH,
ES
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden