Re: Recursion script which doesn't?
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