• 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: Checking on the existence of a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking on the existence of a file


  • Subject: Re: Checking on the existence of a file
  • From: Alex Zavatone <email@hidden>
  • Date: Wed, 24 Oct 2012 13:08:33 -0400

FWIW: My first reaction on reading your mail's title was to use a try block.

Plop some files in your desktop and try out in a simple case to validate your approach.

On Oct 24, 2012, at 12:55 PM, Eric Robertson wrote:

I'm carrying on with my little project to save a sorted list of all the titles of my notes in Evernote into a text file in my Documents/Evernote/Notes folder, basing this on a script I think I found in this list. The name of the text file will normally be "Contents.txt" and if there is an existing file there of that name I want to replace the text with an up to date list of the Evernote note titles otherwise I will set up a new file. I am now using TextWrangler to save away the details!

I thought I could use 'exists' to find out if the file I wanted to use was already there but I couldn't find out how to do this. Instead I decided just to use 'try' and 'on error' when I was producing the alias to the file I wanted to use. This seems to work OK in the following handler:

on save_names(note_names)
set pathToDocuments to (path to documents folder) as text
set pathToFolder to pathToDocuments & "Evernote:Notes:" as text
set fileName to text returned of (display dialog "Set new file name:" default answer "Content.txt")
try
set filePath to (pathToFolder & fileName) as alias
on error
tell application "System Events"
make new file at end of folder pathToFolder with properties {name:fileName}
end tell
set filePath to (pathToFolder & fileName) as alias
end try

tell application "TextWrangler"
set existFile to open filePath
set the contents of existFile to note_names
save existFile
end tell
end save_names

The question I would like to to ask is whether this is a reasonable approach to deal with this situation or whether there is a better one.

Eric


 _______________________________________________
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

References: 
 >Checking on the existence of a file (From: Eric Robertson <email@hidden>)

  • Prev by Date: Re: Checking on the existence of a file
  • Next by Date: Re: Checking on the existence of a file
  • Previous by thread: Re: Checking on the existence of a file
  • Next by thread: Re: Checking on the existence of a file
  • Index(es):
    • Date
    • Thread