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 = ); 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); }