http://www.perlmonks.org?node_id=1066962


in reply to Re^3: Net::FTP::Recursive code not downloading files
in thread Net::FTP::Recursive code not downloading files

Why would I need to run the code for each directory separately? Isn't that the whole point of recursion, so it will drill down into each directory until there are no more levels? The thing is, I don't know where the text files will be within the directory structure, so I have to traverse every directory and subdirectory.

Also, on point about the regex. I tried changing it to the following:

MatchDirs => qr/.*PowerEdge (R810|R610|R720|R620|M620|M1000E).*/,
but I get the same thing.

-- Burvil

Replies are listed 'Best First'.
Re^5: Net::FTP::Recursive code not downloading files
by wazat (Monk) on Dec 13, 2013 at 04:01 UTC

    Net::FTP::Recursive won't descend into to subdirectory unless the name of the subdirectory matches your pattern. For example, if there is a directory

    PowerEdge R810/TextFiles

    Net::FTP::Recursive will descend into "PowerEdge R810" since it matches. However the subdirectory "TextFiles" does not match your pattern, so Net::FTP::Recursive will ignore it. Net::FTP::Recursive dos not consider a child directory to match simply because a parent did.

    What I was suggesting, was that if you happen to know the where the various "PowerEdge" directories are, you could search each of them separately, omitting the MatchDirs option, thus circumventing the limitations of MatchDirs

Re^5: Net::FTP::Recursive code not downloading files
by tangent (Parson) on Dec 14, 2013 at 12:15 UTC
    Why would I need to run the code for each directory separately? Isn't that the whole point of recursion, so it will drill down into each directory until there are no more levels?
    MatchDirs is not doing what you think - it is not saying "if a directory matches this pattern go in and recurse". What it is saying is "for every directory do not enter unless its name matches this pattern". Changing the pattern will not help as it tests against the directory name not the path.

    Peeking into the Module's relevant code may help:

    elsif ( $file->is_directory() ) { if( ( $options{MatchDirs} and $filename !~ $options{MatchDirs} ) or ( $options{OmitDirs} and $filename =~ $options{OmitDirs} )){ next FILE; }