Clars wrote:
> The real hurdle is writing a handler that can continue scanning folders'
> subfolders' subfolders... all the way out of the file structure 'tree',
> and find its way back to the appropriate branching point, when it has
> reached the end of a branch. The point being an orderly, systematic
> sweep of all folders on disk(s).
>
> It seems to me that I can use RECURSION here, but I can't quite get my
> head around it- Can anyone give me some pointers?
My sympathies! Recursion can be a complete headf***.
Someone (I forget who, but am seriously grateful to them!) posted
this simple recursive handler on Direct-L a while back... I've amended
it slightly so that it is now an object rather than a movie script, but
it should get you going:
--<begin object code>--
property pSep, pFileList
on new me
pSep = the last char of the moviePath
pFileList = []
return me
end
on getFileStructure me, whichDir
pFileList = me.directory_driller(whichDir)
return pFileList
end
-- gets all Files in a root folder regardless of depth --
on directory_driller me, whatStartingFolder
whatStartingFolder = whatStartingFolder & pSep
--> "getNthFileNameInFolder" returns folder name without ":" or "\"
counter = 1
repeat while true
deeperName = getNthFileNameInFolder(whatStartingFolder, counter)
if deepername = "" then
-- have gone through all files/folders at given level on first drive
exit repeat
end if
-- "getNth" doesn't return full path, so concatenate
deeperName = whatStartingFolder & deeperName
if NOT DirectoryExists(deeperName) then
-- looking at directory
me.directory_driller(deepername)
else
-- looking at a file
-- save the filename and pathing information
pFileList.append(deeperName)
end if
counter = counter + 1
end repeat
return pFileList
end
--<end object code>--
ok, what this does is to return a list of ALL files in the root folder
(and it's sub folders), but you can filter this by checking extensions,
or filetypes, or whatever, before appending the path to the list.
instantiate the object, and call:
completeFileList = myObj.getFileStructure(rootFolderPath)
good luck,
Christian
----------------------------
Christian Wach
m: +44 (0) 7980 549 556
[EMAIL PROTECTED]
----------------------------
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]