Adding Perl modules?
David Taylor
davidtaylor at writeme.com
Mon Dec 6 22:39:19 PST 2021
I would like to add the Win32::API to the Perl which comes with get_iplayer.
Is that possible?
Here is the script I'm trying to run. It analyses two directories for their
total size and returns an output in a format suitable for MRTG. Perhaps I
should just substitute Win64 for Win32? I've only used Win32 before.
Here's the script in case it clarifies things...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# From: http://www.perlmonks.org/?node_id=2311
# and: https://rt.cpan.org/Public/Bug/Display.html?id=61520
# Note that Windows Vista/Server 2008 or later is required for GetTickCount64.
# This version returns bytes, not MB.
use strict;
use Win32::API;
use Sys::Hostname;
my $GetTickCount;
$GetTickCount = Win32::API->new("kernel32", "int GetTickCount64()");
my $uptime;
my $dir1 = '.';
my $dir2 = '.';
if (@ARGV[0] ne "") {
$dir1 = @ARGV[0];
}
if (@ARGV[1] ne "") {
$dir2 = @ARGV[1];
}
print &dir_tree_size($dir1) . "\n";
print &dir_tree_size($dir2) . "\n";
$uptime = $GetTickCount->Call() / 1000;
printf "%d day(s) %dh %dm\n", int($uptime/86400), int(($uptime/3600)%24),
int(($uptime%3600)/60);
print "PC " . hostname . "\n";
exit 0;
sub dir_tree_size {
my $dir = shift;
my ($i,$total, $f);
$total = 0;
opendir DIR, $dir;
my @files = grep !/^\.\.?$/, readdir DIR;
for $i (@files) {
$f = "$dir/$i";
if(-d $f) {
$total += dir_tree_size($f) }
else {
$total += -s $f}
}
return $total;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks,
David
--
SatSignal Software - Quality software for you
Web: https://www.satsignal.eu
Email: david-taylor at blueyonder.co.uk
Twitter: @gm8arv
More information about the get_iplayer
mailing list