in reply to File::find and skipping directories

Thank you for the suggestions. Alas, it seems I am still missing an important piece of knowledge. I changed my code to this:

find(\&offenders, $dir); sub offenders{ # recurse directories $File::Find::prune = 0; # there are some shared directories # that we do not want to include my @dirs = '\/home\/engineering\/dev\/share'; foreach my $z (@dirs){ #print "$z eq $File::Find::dir\n"; return if ($File::Find::dir =~ m/$z/) } # do not include links return if (-l); # owner of file but skip # if owner is not a user # (uid < 500) # #return if ($uid < 500); $uid = (lstat($_))[4]; if (-d && $uid < 500){ # check do not recurse these # dirctories $File::Find::prune = 1; print "UID is $uid, skipping $File::Find::dir, $File::Find::na +me, $_\n"; return; } # scan only regular files if (-f){ $uname = getpwuid $uid; # gather name of file $fname = $File::Find::name; # size of file (kb) $size = (lstat($_))[7]; $size = int($size/1000); # keep running total of each # user's space use $size{$uname} += $size; } }

This skips everything. Here is the output:

UID is 0, skipping /home, /home, .
Then the program exits.

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re^2: File::find and skipping directories
by sacked (Hermit) on Jun 03, 2004 at 15:49 UTC
    I suggest explicitly checking for a directory named '/home' to allow it:
    if (-d && $uid < 500 and $File::Find::dir ne '/home'){

    Aside, your status message is redundant:
    print "UID is $uid, skipping $File::Find::dir, $File::Find::name, +$_\n"; __END__ UID is 0, skipping /home/zackse, /home/zackse/.kde, .kde
    You can simplify this to:
    print "UID is $uid, skipping $File::Find::name\n"; __END__ UID is 0, skipping /home/zackse/.kde

    Remember that inside the wanted subroutine (offenders in this case), $_ contains the basename,$File::Find::name contains the full path, and $File::Find::dir contains the current directory.

    --sacked