|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
unzip script
hello,
I would be more than very grateful if you could help me on this point: I'm trying to program a little script that downloads (through ftp) and unzips automatically my .tar.gz files. -What i manage: downoad and save on the disk -The problem: i know the file, where it is but don't know what instruction to do to untar and gunzip it... and of course save it again. If any of you has the solution you would be my python hero, thanks! bye |
|
#2
|
||||
|
||||
|
You can probably use the zlib and tarfile modules:
http://docs.python.org/lib/module-zlib.html http://docs.python.org/lib/module-tarfile.html Alternatively, you can build the command string and use os.system Code:
import os cmdstr = "tar -zxvf " + filename + " -C /some/path" os.system(cmdstr)
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
|
#3
|
||||
|
||||
|
Theres an article in devsheds python section on Zipping - written by me
- where this doesn't really apply fully to tar.gz the basic idea is the same so maybe it would be useful.http://www.devshed.com/c/a/Python/Python-UnZipped/ As for the FTP bit you should check out the ftplib module and or search this forum for FTp since the subject comes up every now and again ![]() http://www.python.org/doc/2.3.3/lib/module-ftplib.html Hope this helps some, Mark. Last edited by netytan : May 6th, 2004 at 11:48 PM. |
|
#4
|
|||
|
|||
|
thanks a lot! and thanks also for the reaction time, you were quick!
i'll look at all the links you said and test it! |
|
#5
|
|||
|
|||
|
According to the docs, the tarfile module can open gzipped tar files directly, so you do not even need to mess around with the gzip module. You could download & save the tar.gz file with ftplib, then do:
(warning: untested code. Caveat Emptor) Code:
import tarfile
tar = tarfile.open('path/to/file', 'r:gz')
for member in tar.getmembers():
tar.extract(member, 'output/directory')
Note: the tarfile module was added in Python 2.3, so it will not work if you have an older version. Dave - The Developers' Coach Last edited by DevCoach : May 7th, 2004 at 02:47 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > unzip script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|