Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

monsterzero's scratchpad

by monsterzero (Monk)
on Jun 14, 2006 at 23:24 UTC ( #555382=scratchpad: print w/replies, xml ) Need Help??

Here is some code for zip file
use strict; use warnings; use File::Spec; use Win32::DriveInfo; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $tmpdir = File::Spec->tmpdir(); print "Please supply the file that was downloaded:\n"; chop( my $file_input = <STDIN> ); print "Checking file: $file_input\n"; #check if the files exists if ( -e $file_input && -r $file_input ) { print "Good the file is there and I can read it\n"; } else { die "File $file_input does not exist\n"; } print "Computing extracted size for $file_input \n"; my $file_size = compute_file_size($file_input); my ( $volume, undef, undef ) = File::Spec->splitpath($tmpdir); my $TotalNumberOfFreeBytes = ( Win32::DriveInfo::DriveSpace("$volume") + )[6]; if ( $TotalNumberOfFreeBytes < $file_size ) { print "Not enought space on $volume drive to extract files\n"; die; } else { print "There is enought room to extract the files\n"; } print "Extracting files to $tmpdir\\mpupdate\n"; extract_file($file_input, $tmpdir); sub extract_file { my ($filename, $dir) = @_; my $zip = Archive::Zip->new($filename); my ($volume,$directories ) = File::Spec->splitpath( $dir, 1 ); my $new_dir = File::Spec->catdir( ("$directories", "mpupdate") ); $new_dir .="\\"; my $status = $zip->read( $filename ); die "Read of $filename failed\n" if $status != AZ_OK; $zip->extractTree('', "$new_dir","$volume"); return; } sub compute_file_size { my ($filename) = @_; my $size; my $zip = Archive::Zip->new($filename); foreach my $file ( $zip->members ) { $size += $file->uncompressedSize(); } return ($size); }
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2023-12-02 08:57 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (14 votes). Check out past polls.