Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- From: Bart Lateur <bart.lateur@xxxxxxxxxx>
- Date: Fri, 22 May 2009 12:05:17 +0200
Geoff Cox wrote:
Most of several thousand zip files, on a website, contained a single
Word doc. On moving the files to a CD I extracted all the zip files,
giving them a .doc extension and forgot that a few hundred where
either PowerPoint files or Excel files.
Eh, what?
A ZIP file contains a compressed file tree, including ibnformation of
the exact original filename.
If your users didn't mess up the extensions, then you can just find them
in the archive.
If they used a bad filename (for example, all the same name) but with
the proper extension, then you just have to rename the extracted file,
keeping the extension.
So, if file-22.zip contained fred.ppt, the new file had to be called
file-22.ppt etc.
Like I said.
First extract the ZIP file in the normal way, in a directory of its own.
After that, rename the extracted file, keeping the original extension.
You can move the file to its final dir in one go (as long as the target
dir is on the same drive as the extracted file).
(my $newbasename = $zipfile) =~ s/\.zip$//i;
foreach my $oldname (glob "$extracteddir/*") {
(my $newname = $oldname) =~ s/.*(?=\.)/$dir\/$newbasename/;
rename $oldname, $newname;
}
There's no need to mess with methods of Archive::Zip.
--
Bart.
.
- Follow-Ups:
- Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- From: Peter J. Holzer
- Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- References:
- Prev by Date: Re: Is PERL good for a linguist new to programming?
- Next by Date: Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- Previous by thread: Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- Next by thread: Re: Archive::Zip and correct extension (mixture of Word and PowerPoint files)?
- Index(es):
Relevant Pages
|