• 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: read file subroutine fails every second time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read file subroutine fails every second time


  • Subject: Re: read file subroutine fails every second time
  • From: KOENIG Yvan <email@hidden>
  • Date: Sun, 13 Apr 2008 18:38:37 +0200


Le 13 avr. 2008 à 15:42, MB a écrit :
I'm trying to make a reader subroutine to use in one of my email scripts
and other places, with the objective to move the content of attached
HTML files to the HTML Content of the message in application PowerMail.
First time I run this test of my reader() subroutine it works as
expected, but the second time it gives me a EOF error (-39). How can I
avoid end of file errors in this context?



***The Reader Script on run choose file set theFile to result set theContent to my reader(theFile) -- the main parts only with the call for brevity end run

on reader(theAlias)
	try
		open for access theAlias
	on error
		display dialog "Couldn't read file " & theAlias
		return
	end try

	repeat

		try
			set theFileText to (read theAlias before (ASCII character of 30)
using delimiter (ASCII character of 28))
			return theFileText
		on error myErrMsg number myErrNo
			close access theAlias
			exit repeat
		end try

	end repeat
end reader

***End of reader Script

Hello

If I read correctly, you forgot to close access when the handler doesn't generate an error.

I assumes that inserting

close access theAlias
between the  read and the return  instruction would be useful.

…
set theFileText to (read theAlias before (ASCII character  30)
using delimiter (ASCII character  28))
close access theAlias
return theFileText
…

When I use the open for access instruction I am acustomed to write it differently but I ddon't think that it's the wrongdoer.

Here is my coding:

on reader(theAlias)
	try
		set fileRef to open for access theAlias
	on error
		display dialog "Couldn't read file " & theAlias
		return
	end try

	repeat

		try
			set theFileText to (read fileRef before (ASCII character  30)
using delimiter (ASCII character  28))
close access fileref
			return theFileText
		on error myErrMsg number myErrNo
			close access fileRef
			exit repeat
		end try

	end repeat
end reader

Other detail, I don't understand what is the duo repeat … end repeat supposed to do because the return theFileText instruction exits the loop.

Last nor least, opening for access is perfectly useless.

on reader(theAlias)
try
return read theAlias before (ASCII character  30) ¬
using delimiter (ASCII character  28)
end try
end reader

Would be sufficient

Yvan KOENIG (from FRANCE dimanche 13 avril 2008 18:38:30)


_______________________________________________ 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: 
 >read file subroutine fails every second time (From: MB <email@hidden>)

  • Prev by Date: Quicktime question
  • Next by Date: Re: Quicktime question
  • Previous by thread: read file subroutine fails every second time
  • Next by thread: BBEdit Preview
  • Index(es):
    • Date
    • Thread