in reply to Re^2: Skipping directories using File::Find
in thread Skipping directories using File::Find

find(\&edits, $dir); sub edits { if ($should_prune) { $File::Find::prune = 1 return; } push @$cont, $File::Find::name, stat($File::Find::name) if (!($File::Find::name =~ /.snapshot/)); }

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^4: Skipping directories using File::Find
by doof (Initiate) on Jan 25, 2006 at 11:27 UTC
    But this will still search through the directory wont it? the find function is the one thats doing the traversing so isn't it too late to deal with it in the edits() function?

      It prunes the tree at the current level so any directories below the current one will not be visited and if you return before the edit processing the contents of the current directory are not processed either.

      Remember that, in the normal course of events, edits() will be called for each directory in the tree. Setting prune modifies that behaviour.


      DWIM is Perl's answer to Gödel
        Fantabulous, it seems to work. How come you dont have to reset prune to 0 after than directory?

        Thanks for everyones help