rendered paste bodyuse strict;
IRC::add_command_handler("makelist", "makelist");
sub makelist
{
IRC::print "Making list\n";
open(FILELIST, ">/home/inithello/fserver/listfile.txt");
open(INDEX, ">$/home/inithello/fserver/index.txt");
use File::Find;
find (\&process, "/home/inithello/apollo");
close INDEX;
close FILELIST;
}
sub process
{
my $filename = $_;
my $filepath = $File::Find::dir;
my $numfiles;
my $totalsize;
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $therest) = stat($_);
if (!(-d $_))
{
$totalsize += $size;
print FILELIST ("$filename ");
my $bah = 0;
while ($bah <= (80 - length ($_)))
{
print FILELIST "-";
$bah++;
}
my $mbsize = $size / 1024**2;
my $kbsize = $size / 1024;
if ($size > 1024 && $size < 1024**2)
{
print FILELIST (" $kbsize kB\n");
}
elsif ($size > 1024**2)
{
print FILELIST (" $mbsize MB\n");
}
else
{
print FILELIST (" $size B\n");
}
print INDEX ("$filepath:$filename\n");
$numfiles++;
}
IRC::print "$totalsize bytes in $numfiles files";
}
Undesired output:
Making list
bytes in files
17245 bytes in 1 files
23 bytes in 1 files
6941 bytes in 1 files
517841 bytes in 1 files
1887 bytes in 1 files
4950429696 bytes in 1 files
4119 bytes in 1 files
0 bytes in 1 files