Recursive Directory Walker for really huge numbers of files

Sivakatirswami katir at hindu.org
Thu May 9 17:43:01 EDT 2002


Case is closed, but this may be useful to others:

Regarding the recursion on the directory walk script that I was
experiencing... aside from file names and folders containing slashes...I
discovered another weird anomaly/../anomaly../anomaly....

The script started returning

baseDirectory/some folder/../../../../../../../../../

and the end of this started growing infinitely.

When I did this from our OSX server, I got this:

Live Web Site BackUps/www.himalayanAcademy.com/../store.himalayanacademy.com
../store.himalayanacademy.com../store.himalayanacademy.com../store.himalayan
academy.com

etc until I have to break with cmd .  So, I asked the script to simply list
the folders at the top level and then bail out and I got this

-images
..
art
books
cg-bin
hawaii

etc.

But you cannot see that folder ".."; you cannot search for it in Sherlock...
if that folder ".." exists in a directory on the server  and you copy that
directory to your hard drive, it will be there also, then the recursive
directory walk will also fail on that line... I don't understand it at all,
but thought just to skip that folder and it should work... it did:

So, I added a line to prevent that folder from being returned to the dig

put the folders into tDirList
  sort tDirList
  put whatFolder & cr & cr & tDirList
delete line 1 of tDirList
  repeat for each line x in tDirList
    if x = ".."  then next repeat    ## skip that folder
   directoryWalk (whatFolder & "/" & x)
end repeat

And then, the problem disappeared. And you are right Geoff, incredibly fast:
6 seconds to dig for a file list of 5210 files on the server on the...
great!

thanks!

Sivakatirswami
Editor's Assistant/Production Manager
katir at hindu.org 
www.HinduismToday.com, www.HimalayanAcademy.com,
www.Gurudeva.org, www.hindu.org

Read The Master Course Lesson of the Day at
http://www.gurudeva.org/lesson.shtml




More information about the metacard mailing list