[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] File/Folder Iteration



Strider writes:
|the &iterate function
|takes the directory sent to it
|adds it to the "path" variable
|readdir's the new path
|adds the file sizes to a 'total' variable
|&iterate's for each directory in path
|returns total size

Other than naming a recursive function 'iterate' (:-)), it looks fine.
This is one of the standard idioms for traversing a directory structure.
(The other uses chdir so you don't have to maintain a full path, but
error recovery is harder.)

|Debugging says that I go 100 deep in recursions on my first iteration
|(maybe I'm misintepreting that- probably, in fact) and I'm thinking of
|using a slightly different system that doesn't involve returning variables,
|and therefore uses less memory in my() variables for each iteration.

You should only get as deep as the directory structure on your disk,
which probably isn't 100 levels deep. So:

- You have a problem on your disk. It's possible, if your disk's directory
structure is screwed up, to have a loop, so the above will recurse until
MacPerl runs out of memory. Run Norton Utilities or Disk First Aid on
the disk. [As an aside, if you plan on running the script on Unix, you
have to filter out the directories '.' and '..', which (purposefully)
introduce loops into the directory tree. You also have to watch out for
links and symlinks (I guess you have to watch out for symlinks in MacPerl
too).], or
- There's a problem with your code. Although the algorithm above is
essentially correct, something may have went wrong in the translation
to code, or
- You're misinterpreting how deep you really are.

So, your general approach is correct. You probably either have a coding
error or a screwed up disk is causing problems.

Brian

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch