Re: does anybody have a recursive directory subrountine???
Re: does anybody have a recursive directory subrountine???
- Subject: Re: does anybody have a recursive directory subrountine???
- From: Ric Phillips <email@hidden>
- Date: Thu, 13 Sep 2001 14:10:24 +1000
On 13/9/01 11:27 AM, "Ric Phillips" <email@hidden> wrote:
Just an 'oops' about the code below - posted earlier today with explanation.
The variable 'root' is a string of the form "MacHD:Folder 1:Folder 2:".
That's what you need to pass in in the first place - remembering to ensure
that the initial string terminates in a ":".
Also note that because of this you can't use root as a variable carrying an
alias - that is,
'count of every file in root' --> will not work
'count of every file in folder root' --> will work just fine
Apologies to anyone caught out by my not point this out.
>
>
-- Start code snippet
>
>
on processTree(root)\n
>
>
tell application "Finder"\n
>
-- Code to prcess files at current level\n
>
if (count of every file in folder root) > 0 then\n
>
set filesInRoot to the name of every file in folder root as list\n
>
repeat with thisfile in filesInRoot\n
>
try\n
>
-- Place specific file processing code here.\n
>
-- eg: get the name or path and add it to a global list.\n
>
-- Note: Try wrapper. Lack of error handling on one \n
>
-- exception will halt all processing on tree.\n
>
-- Put in your own error routine (to write an error log\n
>
-- or just display an informative dialog for example)\n
>
end try\n
>
end repeat\n
>
end if\n
>
-- Code for Re-entrant navigation of tree\n
>
if (count of every folder in folder root) > 0 then\n
>
set theseFolders to the name of every folkder in folder root as list\n
>
repeat with thisFolder in theseFolders\n
>
set oldRoot to root\n
>
set root to root & thisFolder & ":"\n
>
my processTree(root)\n
>
set root to oldRoot\n
>
end repeat\n
>
end if\n
>
end tell\n
>
>
end processTree \n
>
>
-- End code snippet.
>
Ric Phillips
Computer Laboratory Support Officer
Faculty of Humanities and Social Sciences
La Trobe University
9479 2792