• 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: Recursion script which doesn't?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recursion script which doesn't?


  • Subject: Re: Recursion script which doesn't?
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 4 Apr 2001 15:23:43 +0100

Charles Arthur wrote on Tue, 3 Apr 2001 18:47:17 +0100:

>Hi ...
>
>Maybe I'm not understanding how recursive subroutines should work, but I'm
>getting some very odd ones with this one (which is meant to look through a
>group of folders finding files newer than a particular date, for later
>copying). (This is what thefilelist is meant to become.)
>
>I find that when I choose a folder just containing files that it returns
>errors where the variable "afolder" seems to have retained its value into
>the recursion, rather than being parked for a new iteration of the
>recursion. Hence the various dialogs added to the script, to find out where
>it is and what it's operating with.
[...]


Your script works on both my 8.6 and 9.0.4 machines if I remove the
'display dialogs' and 'activates' and make 'lastrundate' into a global or
a property. However, it would be more efficient - and the logic clearer -
like this:

set lastrundate to date "Thursday, 14 December 2000 00:00:00"
set afolder to choose folder
comparefiles(afolder, lastrundate)

on comparefiles(afolder, lastrundate)
set thefilelist to {}
tell application "Finder"
set theFiles to (every file of afolder) as list
repeat with afile in theFiles
if modification date of afile comes after lastrundate then
set end of thefilelist to (contents of afile)
end if
end repeat
set theFolders to (every folder of afolder) as list
repeat with afolder in theFolders
my comparefiles(afolder, lastrundate)
set thefilelist to thefilelist & the result
end repeat
end tell
return thefilelist
end comparefiles

I'm not sure if using 'lastrundate' as a parameter instead of a global is
actually more efficient, but it's generally considered to be better
practice.

NG


  • Follow-Ups:
    • Re: Recursion script which doesn't?
      • From: Hugh Dixon <email@hidden>
  • Prev by Date: Re: Has anyone gotten this: [NoLimitTravel]
  • Next by Date: Re: When did Remote Access Commands get depreciated?
  • Previous by thread: Recursion script which doesn't?
  • Next by thread: Re: Recursion script which doesn't?
  • Index(es):
    • Date
    • Thread