• 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 a file - Lion vrs Tiger
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read a file - Lion vrs Tiger


  • Subject: Re: read a file - Lion vrs Tiger
  • From: "koenig.yvan" <email@hidden>
  • Date: Wed, 26 Sep 2012 20:45:44 +0200


Le 26/09/2012 à 19:26, Jim Brandt <email@hidden> a écrit :

I have a question about reading files in Lion vrs Tiger.

I have a script that is running very sluggishly under Lion on a Mac Mini. This same script ran much faster under Tiger, so I've been trying to figure out why.

The script is very long and involved so I'm breaking the testing up into pieces. The first thing it does is read several HTML files and strip out rows of a table from each file. Each HTML page is between 6 and 7 K in size.

So I timed this piece of the script.

Here's the main part of this piece of the script:

set theList to FileLib's GetFileListOfFolder(HTMLFolder, false) -- get files in HTML folder

set RowSearchStr to "<td class=\"lc1\">.*?</tr>"
set TitleSearchStr to "<title>.*?</title>"
set AllRows to {}
tell application "TextCommands" to set startTime to lowercase (time string of (current date))

repeat with eachFile in theList
   tell application "Finder" to set nm to name of eachFile
   tell application "Finder" to set knd to kind of eachFile as text 
   if not (nm begins with " ") then -- skip files beginning with a space
      if (knd is "Document") or (knd is "HTML document") then
         set fileCnt to fileCnt + 1
         set theFile to eachFile as alias
         -- read the file
         set FileRef to open for access theFile
         set DocumentText to read FileRef
         close access FileRef
         
         tell application "TextCommands" to set Rows to search DocumentText for RowSearchStr with regex
         set AllRows to AllRows & Rows -- append
      end if
   end if
end repeat

tell application "TextCommands" to set StopTime to lowercase (time string of (current date)) -- debug

set totalCnt to count of AllRows
set mess to "Start: " & startTime & return & "Stop: " & StopTime & return & return -- debug
set mess to mess & "Possible files: " & (totalCnt as text) & " found in " & (fileCnt as text) & " files." -- debug
display dialog mess with title appTitle -- debug


No idea about the difference between the two operating systems.

Here are some proposed changes :

edit
   tell application "Finder" to set nm to name of eachFile
   tell application "Finder" to set knd to kind of eachFile as text 

as

   tell application "Finder" to tell eachFile to set { nm, knd } to {name, kind  as text }

edit
if (knd is "Document") or (knd is "HTML document") then
as
if knd is in  {"Document",  "HTML document"} then

edit
         -- read the file
         set FileRef to open for access theFile
         set DocumentText to read FileRef
         close access FileRef
as
     -- read the file
         set  DocumentText to read theFile

As far as I know, using open for access is not needed when you just read and close the file immediately.

Yvan KOENIG (VALLAURIS, France) mercredi 26 septembre 2012 20:45:39


 _______________________________________________
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 a file - Lion vrs Tiger (From: Jim Brandt <email@hidden>)

  • Prev by Date: Re: read a file - Lion vrs Tiger
  • Next by Date: Re: read a file - Lion vrs Tiger
  • Previous by thread: Re: read a file - Lion vrs Tiger
  • Next by thread: Re: read a file - Lion vrs Tiger
  • Index(es):
    • Date
    • Thread