|
Posted by Jim Gibson on January 2, 2007, 5:40 pm
Please log in for more thread options
> Hello All,
>
> I'm new to perl and I'm attempting to write a script that does the
> following:
>
> 1) Open the directory and copy the .zip1 file name to a variable
> 2) create a new directory (using the .zip1 file name as the name of the
> new directory.)
> 3) Unzip the .zip1 file to it's newly created directory.
> 4) Edit the files that were unzipped to the directory.
> 5) Zip the edited files to a new .zip1 file and put them in a FINISHED
> directory.
>
> Here's what I have so far.
>
> #!/usr/bin/perl -w
>
> use strict;
> use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
>
> my $zip = Archive::Zip->new();
> my $workdir; #Working directory where zip1 are unpackaged
> my $tempdir;
> my $status;
>
> print "\n\nScanning directory for .zip1 files...\n\n";
>
> opendir(DIR,".");
>
> while ($workdir=readdir(DIR))
> {
> if($workdir =~ /zip1/)
> {
> mkdir $workdir."_UNPACKED";
> $tempdir = $workdir."_UNPACKED";
> print "Creating Working Directory: $tempdir\n";
> $status = $zip->read($workdir);
> die "Read of $workdir failed\n" if $status != AZ_OK;
> $zip->extractTree($workdir, $tempdir);
Read the documentation for extractTree. The first argument is not the
name of the zip file, it is the root name of all of the files in the
zip file to be extracted. If none of the files stored in the zip file
have the same root name as the name of the zip file itself (a likely
occurrence), no files will be extracted. Try cd'ing to the destination
directory and using extractTree with no arguments. Try using '' as the
first argument. If those don't work, try accessing the names of the
zipped files (with members() perhaps) and extracting them individually.
I have not used Archive::Zip and am just suggesting possibilities from
the documentation.
> }
>
> }
>
> closedir(DIR);
> print "\n";
> exit;
>
> The directories are created, but the .zip1 files are not unzipped to
> the created directories ($tempdir).
> Any advice will be appreciated. Thanks.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
|