Hi,
Can someone spot and explain what I am doing wrong.
I have a script that should read the contents of a CD (on Win32). I
want a summary at the top of the page of what I've found. I use find
to count the files and dirs and I want the total files ($in) to be a
the top before I list the files. Once I have printed the header stuff
("Content of ..."), I store the position of the filehandle so I can
come back to that position later but I am always truncating existing
text so my output reads like this:
CD Has 4 folders:
a, e, g, n,
Total number of files: 38486
38486jpg
1224.jpg
1225.jpg
...
When i desire this:
CD Has 4 folders:
a, e, g, n,
Total number of files 38486
--------------------------
1221.jpg
1222.jpg
...
The text starts in the expected place but although I have created 12
newlines for the summary text (that should only use 9 lines) the text
crashes into listing sucking up any spare newlines as it goes.
Am I making sense?? Any ideas?
Dp.
=============
use strict;
use warnings;
use Win32API::File 0.08 qw(GetVolumeInformation );
use File::Find;
$| = 1;
my $in = 0;
my $sRootPath = 'e:/';
my
($osVolName,$lVolName,$ouSerialNum,$ouMaxNameLen,$osFsType,$ouFsFlags,
$lFsType);
GetVolumeInformation( $sRootPath, $osVolName, $lVolName,
$ouSerialNum, $ouMaxNameLen, $ouFsFlags, $osFsType, $lFsType );
my $file = $osVolName.'.txt';
open(LOG,">$file") or die "Can't write $file: $!\n";
print LOG "Contents of Disk with Volume Name $osVolName\n\n";
my $pos = tell LOG;
print LOG "\n\n\n\n\n\n\n\n\n\n\n\n"; # Add space for summary.
print LOG "-------------------------\n";
my @dirs;
my %uniq;
find(\&files,$sRootPath);
# Summary text.
seek(LOG, $pos, 0);
print LOG "CD Has ",($#dirs + 1)," folders: ";
for (@dirs) {
print LOG "$_, ";
}
print LOG "\n\nTotal number of files: $in\n";
sub files {
my $section;
($section) = ($File::Find::dir =~ /$sRootPath(\w{1})/);
# unique folder only
if (! exists($uniq{$section}) && $section =~ /\w/) {
push(@dirs,$section);
$uniq{$section} = 0;
}
# Count the files and print em'
if ($_ =~ /jpg/i) {
++$in;
print LOG "$section\t$_\n";
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/