• 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
Slow Repeating Loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Slow Repeating Loop


  • Subject: Slow Repeating Loop
  • From: Damon Casey <email@hidden>
  • Date: Fri, 19 Jan 2007 15:30:19 +0000
  • Thread-topic: Slow Repeating Loop

Hi,

I'm having problems with a script that loops through Finder folders
capturing files that were modified yesterday to a list and then copying
those files to a new location.

The folder in question is stored on a remote Unix server whose file system
is NFS. The LAN is running at 100Base-T. The Mac running the script is a 17"
Intel iMac running 10.4.8.

The folder currently has 80GB of images in sub-folders and the script is
taking hours to get halfway through the sub-folders.

The script starts off quickly, and over time, slows to a crawl. Originally,
when choosing the folder to process, I created a list of the folder's entire
contents.

I've tried to speed things up by making a list of the first sub-folder,
dealing with the modified files, setting the list variable to an empty list,
then moving on to the next sub-folder. This did speed things up somewhat,
but still grinds to a halt.

I'm guessing the problem is the amount of information AppleScript is
committing to memory. I thought that by making a small list of the first
sub-folder, processing the list, then initialising the list by setting it to
an empty list would reduce the amount of memory the script would use. Am I
doing something fundamentally wrong with my lists or repeat loops that could
cause this problem? I've included the entire script below.

Regards,
--
Damon Casey
Automating Data Ltd.
mailto:email@hidden





-- Initialise variables and properties
set {FileList, ImageList, ModYesterdayList, MissingValueList} to {{}, {},
{}, {}}
set PathToDesktop to (path to desktop as string)

global MyText, LogFile

-- Capture yesterday's date
set ModYesterday to ((current date) - 86400) -- 1 day in seconds
set ModYesterday to short date string of ModYesterday

--
============================================================================
=====================================

-- The following routine is for testing purposes only. It must be changed to
the predefined folder path before the script is put into production
set DestinationFolderName to "MY_Destination Folder"
set DestinationFolder to PathToDesktop & DestinationFolderName

tell application "Finder"
    if exists folder DestinationFolder then
        -- Do nothing
    else
        make new folder at desktop with properties
{name:DestinationFolderName}
    end if
end tell

--
============================================================================
=====================================

-- Choose the image folder and create a list files
set OriginalFolder to choose folder with prompt "Choose the folder of images
to copy:"

-- Create the log file
my LogFileName()
set MyText to "The following folder was chosen for processing:" & return &
return & OriginalFolder & return & return &
"============================================================" & return &
return & return & "The following files were copied to the destination
folder:" & return & return
open for access file LogFile with write permission
write MyText to file LogFile
close access file LogFile


try
    -- Allow 100 minutes to produce the lists
    with timeout of 6000 seconds
        tell application "Finder"

            -- set OriginalFileList to entire contents of OriginalFolder
            set FolderList to every folder of OriginalFolder
            set FileList to every file of OriginalFolder

            -- Create the list of images
            my CreateImageList(FileList)

            -- Create the modified yesterday list
            my ModList(ImageList)

            -- Copy the images and then initialise the list
            duplicate ModYesterdayList to folder DestinationFolder
            set {ModYesterdayList, ItemList, FileList, ImageList} to {{},
{}, {}, {}}

            -- Write the log to  the log file
            -- my WriteLogFile(OriginalFolder)
            open for access file LogFile with write permission
            write MyText to file LogFile
            close access file LogFile

            set MyText to ""

            repeat with i from 1 to count of FolderList
                set ItemList to entire contents of item i of FolderList

                -- Filter the list to hold only files - discard folders
                repeat with i from 1 to count of ItemList
                    if class of item i of ItemList is folder then
                        -- Do nothing
                    else
                        -- It's a file, add it to the FileList
                        set end of FileList to item i of ItemList
                    end if
                end repeat


                -- Create the list of images
                my CreateImageList(FileList)

                -- Create the modified yesterday list
                my ModList(ImageList)

                -- Copy the images and then initialise the list
                duplicate ModYesterdayList to folder DestinationFolder
                set {ModYesterdayList, ItemList, FileList, ImageList} to
{{}, {}, {}, {}}




                -- Write the log to  the log file
                -- my WriteLogFile(OriginalFolder)
                open for access file LogFile with write permission
                write MyText to file LogFile
                close access file LogFile

                set MyText to ""
            end repeat


            display dialog "The script processed the chosen images
successfully!" & return & return & "A log file has been saved to your
Desktop." buttons {"OK"} default button 1

        end tell
    end timeout
on error errMsg number errNum
    display dialog "There was an error while processing the chosen files!" &
return & return & errMsg & " " & errNum buttons {"OK"}
end try




--
============================================================================
=====================================
-- Subroutines
--
============================================================================
=====================================

-- Create the log file name

on LogFileName()
    set CurrentDate to current date
    -- Capture the date and time as strings
    set FileDate to ((day of CurrentDate) & "-" & (month of CurrentDate as
integer) & "-" & (year of CurrentDate)) as string
    set FileTime to time string of CurrentDate
    -- Capture the elements of the time
    set TempDelimiters to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ":"
    set TimeItems to text items of FileTime
    set AppleScript's text item delimiters to TempDelimiters
    -- Configure the time using server-legal characters
    set FileTime to ""
    repeat with i from 1 to count of TimeItems
        set FileTime to FileTime & text item i of TimeItems
        if i < (count of TimeItems) then
            set FileTime to FileTime & "_"
        end if
    end repeat
    -- Create the file name string
    set FileDate to FileDate & " at " & FileTime
    set LogFile to my PathToDesktop & "Modified Yesterday " & FileDate &
".txt"
end LogFileName




-- Create the list of images
on CreateImageList(TheList)
    -- Filter the list to hold only image files (they can be any image type
too)
    repeat with i from 1 to count of TheList
        if (file type of item i of TheList contains "JPEG") ¬
            or (file type of item i of TheList contains "EPS") ¬
            or (file type of item i of TheList contains "PDF") ¬
            or (file type of item i of TheList contains "TIFF") ¬
            or (file type of item i of TheList contains "Photoshop") then
            set end of my ImageList to item i of TheList
        else if file type of item i of TheList = missing value then
            set end of MissingValueList to item i of TheList
        end if
    end repeat
end CreateImageList




-- Create the modified yesterday list
on ModList(TheImageList)
    repeat with i from 1 to count of TheImageList
        set TempFileModDate to (modification date of item i of TheImageList)
        set TempFileModDate to (short date string of TempFileModDate)
        if TempFileModDate = my ModYesterday then
            set end of my ModYesterdayList to item i of TheImageList
            -- Capture the file path for the log file
        end if
    end repeat
    repeat with i from 1 to count of my ModYesterdayList
        set my MyText to my MyText & (item i of my ModYesterdayList as alias
as string) & return
    end repeat
end ModList


 _______________________________________________
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/mailman//archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Text items
  • Next by Date: Re: PS CS art layer solid fill
  • Previous by thread: Re: Checking If A Finder Window Is Already Open
  • Next by thread: [ann] Appscript Installer 1.5, rb-appscript 0.3.0 released
  • Index(es):
    • Date
    • Thread