Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2017-07-20 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (313 votes). Check out past polls.