in reply to Re^8: Help with $File:Find
in thread Help with $File:Find

I'm calling find in a sub , passing the $dir variable on each call. The nodirs sub called from "find" excludes any sub directories found within $dir. The "return unless" maybe redundant, but may also help to exclude anything that isn't a real file. I'm going to let this run for a few weeks to see if the original issue returns.
find( { wanted => \&get_files, preprocess => \&nodirs }, "$BASEDIR +/$dir" ); sub nodirs { grep !-d, @_; } sub get_files { return unless ( -f $_ ); my $tmpfile = $File::Find::name if ( ($_) && ( (/^(?!\.).*\.($ +INTYPES)$/i) || ( (/^(?!\.).*\.($INTYPES)\.($ENGZTYPES)$/i) && !(/\.( +$OUTTYPES)\.($ENGZTYPES)$/i) ) ) ); if ( $tmpfile ) { if ( ( exists( $globalfiles{$tmpfile} ) ) && ( ( $globalfi +les{$tmpfile} ne 'submitted' ) || ( $globalfiles{$tmpfile} ne 'workin +g' ) ) ) { return; } else { if ( -e $tmpfile ) { my $lckfile = getlckfile($tmpfile); push @tmparray, $tmpfile unless ( -e $lckfile ); } } } }

Replies are listed 'Best First'.
Re^10: Help with $File:Find
by Marshall (Canon) on Feb 22, 2018 at 21:18 UTC
    I did some more testing to try to figure this out because your reported rare symptoms are weird.

    Much to my surprise, the preprocess routine in File::Find does affect the subsequent directory traversal in File::Find.
    From the documentation, I didn't think that it would do that, but it apparently does.

    The nodirs() sub will leave the initial starting results directory in the results to be used by get_files();

    There is no need to use File::Find here because you are only looking at files in the base directory and not navigating to subdirectories.
    I would consider just using opendir (my $handle, "dirname") or die "$!" and use readdir(). I am unable to simulate a situation to reproduce your symptoms on my current computer. An unlocked data structure would explain this.

    From your code, it appears that this is a multi-process application. Right now, I am thinking that perhaps there is some rare situation where $BASEDIR/$dir doesn't exist.

    #!/usr/bin/perl use strict; use warnings; use File::Find; find( { wanted => \&get_files, preprocess => \&nodirs }, "C:/test" ); sub nodirs { grep !-d, @_; } sub get_files { #return unless ( -f $_ ); #testing without this statement # prints: # C:/test <- this is a directory nevertheless! # C:/test/SomeBogusFile.txt return unless ( -f $_ ); #testing with this statement # prints: # C:/test/SomeBogusFile.txt print "$File::Find::name \n"; } __END__ Test Directory structure C:/test SomeBogusFile.txt /subdirtest docinbsubdir.txt