J
John N.
I am new to Perl. I have a Sun box running Solaris 8 and the Perl that
comes with the OS.
I pulled some code off of Sun's site that searches a directory tree
and finds big files. When I run the program it works except that it
does not find files over 5 GB.
I have done a few things to trouble shoot the code and I found that it
fails in two places. On the line of "elsif ((-f _) && (! -l $path))"
the file fails the -f switch test. When I do a ls -l on the directory
it shows that the file is a normal file with the same rights as the
other files in the directory. Then I took "-f _" logic check out and
printed the result of the "$size = -s $path;" code and the -s returns
a blank for the size.
Do I have to do differant things with large files? Are there bugs or
limitations on the -f and -s switches? How do I make the code work?
Thanks for your help,
John
#
# scan throught the directory tree
#
&traverse('.');
sub traverse {
local($dir) = shift;
local($path);
unless (opendir(DIR, $dir)) {
warn "Can't open $dir\n";
closedir(DIR);
return;
}
foreach (readdir(DIR)) {
next if $_ eq '.' || $_ eq '..';
$path = "$dir/$_";
if ((-d $path) && (! -l $path)) { # non-symlink dir, enter it
&traverse($path);
} elsif ((-f _) && (! -l $path)) { # plain file, but not a
symlink
$size = -s $path; # get the size in bytes
$ksize = $size / 1000; # convert to megabytes
if ($size > $minsize) {
$age = -A $path; # get the age in days
printf "%9d Kilobytes %4d days
%s\n",$ksize,int($age),$path;
}
}
}
closedir(DIR);
}
comes with the OS.
I pulled some code off of Sun's site that searches a directory tree
and finds big files. When I run the program it works except that it
does not find files over 5 GB.
I have done a few things to trouble shoot the code and I found that it
fails in two places. On the line of "elsif ((-f _) && (! -l $path))"
the file fails the -f switch test. When I do a ls -l on the directory
it shows that the file is a normal file with the same rights as the
other files in the directory. Then I took "-f _" logic check out and
printed the result of the "$size = -s $path;" code and the -s returns
a blank for the size.
Do I have to do differant things with large files? Are there bugs or
limitations on the -f and -s switches? How do I make the code work?
Thanks for your help,
John
#
# scan throught the directory tree
#
&traverse('.');
sub traverse {
local($dir) = shift;
local($path);
unless (opendir(DIR, $dir)) {
warn "Can't open $dir\n";
closedir(DIR);
return;
}
foreach (readdir(DIR)) {
next if $_ eq '.' || $_ eq '..';
$path = "$dir/$_";
if ((-d $path) && (! -l $path)) { # non-symlink dir, enter it
&traverse($path);
} elsif ((-f _) && (! -l $path)) { # plain file, but not a
symlink
$size = -s $path; # get the size in bytes
$ksize = $size / 1000; # convert to megabytes
if ($size > $minsize) {
$age = -A $path; # get the age in days
printf "%9d Kilobytes %4d days
%s\n",$ksize,int($age),$path;
}
}
}
closedir(DIR);
}