1827667 Members
4004 Online
109966 Solutions
New Discussion

Perl: File::Find

 
David_246
Trusted Contributor

Perl: File::Find

Hi,

I would like to search a starting directory and get it's contens (du -ks). Now I thougth I had used the File::Find module correct, but when there are no files in a directory, it will just not be "found".

use File::Find;
..
.
find(\&wanted, $directory);

sub wanted {
$dir = "$File::Find::dir";

unless ($seen{$dir}++) {
next if ( $dir =~ lost+found );
next if ( $dir eq $directory );
$dm=`du -ks $dir 2>/dev/null`;
($kb, $path) = split /\s+/, $dm ;
$mb = int( $kb / 1024 );

$output{$path} = $mb;

}
}

Of course this is only a very small part of the script. But as told I need only directories (that are uniq). Now File::Find only traces files, so a directory without files, just does not gets parsed.
I cannot find a module Dir::Find. Is there anyone that has a solution for this?

Regs David
@yourservice
1 REPLY 1
Jerome Henry
Honored Contributor

Re: Perl: File::Find

Maybe this one could help you :
http://search.cpan.org/~kwilliams/Path-Class-0.03/lib/Path/Class/Dir.pm

hth

J
You can lean only on what resists you...