Directory Walker revisited

Monte Goulding monte at sweattechnologies.com
Wed Sep 3 20:44:01 EDT 2003


> I'm a tiny bit worried that hitting the recursion limit with the
> directory walker might be indicative of something surprising that is
> going to jump up and bite me later.


Some supprising Results on the following test:

Result: 0.931,0.915 (on my My Documents directory which is quite big)
Note it's even faster if you do a direct call instad of send but I've used
send because one would assume it would avoid recursion issues.

So it would seem the handler version is faster

local lList = ""

on mouseUp
  answer folder ""
  put it into tFolder
  put the long seconds into tSeconds
  get walkDir(tFolder)
  put the long seconds-tSeconds into tFunction
  put the long seconds into tSeconds
  hWalkDir tFolder
  put the long seconds-tSeconds into tHandler
  put tFunction,tHandler
end mouseUp

-- This recursive function expects a folder path.
-- It returns a file list for that folder and for each
-- sub-folder it contains (pre-order search)
-- Invisible files are excluded.
function walkDir dirPath
  put empty into tList
  set defaultFolder to dirPath
  put the long files into fList
  repeat for each line fLine in fList
    if char 1 of fLine <> "." then
      put item 1 of fLine & comma & last item of fLine into fData
      put dirPath & "/" & fData & return after tList
    end if
  end repeat
  get the folders
  repeat for each line x in it
    if char 1 of x <> "." then
      put walkDir(dirPath & "/" & x) after tList
    end if
  end repeat
  return tList
end walkDir

-- This recursive function expects a folder path.
-- It returns a file list for that folder and for each
-- sub-folder it contains (pre-order search)
-- Invisible files are excluded.


on hWalkDir dirPath
  set defaultFolder to dirPath
  put the long files into fList
  repeat for each line fLine in fList
    if char 1 of fLine <> "." then
      put item 1 of fLine & comma & last item of fLine into fData
      put dirPath & "/" & fData & return after lList
    end if
  end repeat
  get the folders
  repeat for each line x in it
    if char 1 of x <> "." then
      send hWalkDir && dirPath & "/" & x to me
    end if
  end repeat
end hWalkDir




More information about the use-livecode mailing list