• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to detect if a file exists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: How to detect if a file exists
      • From: "Mark J. Reed" <email@hidden>
References: 
 >How to detect if a file exists (From: Andrew P <email@hidden>)

  • Prev by Date: Re: open for access file
  • Next by Date: Re: open for access file
  • Previous by thread: How to detect if a file exists
  • Next by thread: Re: How to detect if a file exists
  • Index(es):
    • Date
    • Thread