Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unzipping a file from a perl script . . . 1

Status
Not open for further replies.

youthman

Programmer
Apr 28, 2004
49
US
Good day to all!

I am a VERY new perl programmer and I have run into an interesting problem.

I am receiving a series of files by FTP each day. The first set is a flat-file database that is overwritten each day. The second is a zip file containing a series of images for the day saved by the date. (Today's date is April 28, 2004 and so the file is: 04282004.zip)

I need to be able to automatically unzip this file to a specific directory each day after it arrives. (All the images will go into the same /pics/ directory.

I have tried to look at the information on cpan but being new, it is VERY confusing! ANY HELP?!?!?!?!

youthman

 
Youth,

The Perl function "system" calls stuff as though you were at a command prompt. Check out the winzip documentation for shell usage, but I imagine your solution would look something like this:

system(winzip someFolder/myzipfile.zip /extractionFolder);

Good luck,

Nick
 
I have tried this and it doesn't seem to work in any fashion! I am running this script remotely on a hosting server. It is not a physical box that I have control over, so, I am somewhat limited. It is also a Unix based system. I don't think it has "winzip" on it, but I tried to use pkzip, and that was also unsuccessful. Anyone else got ideas?!?!?!?!
 
That is great, now on to the next problem with that . . . is there a way to install this on a remote server that does not give me shell access? I am placing this on a hosting acount that I do not have telnet into. All I can do is FTP.
 
If you're on UNIX, and you don't want to download Archive::Zip, then try something like:
Code:
$zipfile = "a.zip";
open (ZIPFILES, "unzip $zipfile|");
while (<ZIPFILES>) {
    ## do something with the file that has been unzipped
}
close ZIPFILES;
Cheers, Neil
 
Yes, you can put it into your shell script's current directory in a directory called Archive - it should get picked up by your script from there.

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Thank you toolkit! You are a LIFESAVER!!! One last thing . . . Is there a way to set the directory that the files get written to, and to set the preferences for overwrite?
 
The usage for my version of unzip says:
[quoute]
UnZip 5.32 of 3 November 1997, by Info-ZIP. Maintained by Greg Roelofs. Send
bug reports to the authors at Zip-Bugs@lists.wku.edu; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip]
  • [-x xlist] [-d exdir]
    Default action is to extract files in list, except those in xlist, to exdir;
    file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage).

    -p extract files to pipe, no messages -l list files (short format)
    -f freshen existing files, create none -t test compressed archive data
    -u update files, create if necessary -z display archive comment
    -x exclude files that follow (in xlist) -d extract files into exdir

    modifiers: -q quiet mode (-qq => quieter)
    -n never overwrite existing files -a auto-convert any text files
    -o overwrite files WITHOUT prompting -aa treat ALL files as text
    -j junk paths (do not make directories) -v be verbose/print version info
    -C match filenames case-insensitively -L make (some) names lowercase
    -X restore UID/GID info -V retain VMS version numbers
    -M pipe through "more" pager
    Examples (see unzip.doc for more info):
    unzip data1 -x joe => extract all files except joe from zipfile data1.zip
    unzip -p foo | more => send contents of foo.zip via pipe into program more
    unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
    [/quote]
    So it looks like the -d and other options will help you out. Note that if you just want to unzip the file, you can use system("unzip -d $somedir $somefile"), similar to Nebbish's suggestion.
 
Thank you to ALL!!!! A combination of all your information and it is working great now!!! THANK YOU!!!

No more replies needed for this thread!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top