B
Bartolomé Sintes Marco
Hi,
In this mail,
http://www.mail-archive.com/[email protected]/msg00030.html
Kragen Sitaker explained how to unzip a file in Python
#!/usr/local/bin/python
# learn how to use zipfile module
import sys, zipfile, os, os.path
def unzip_file_into_dir(file, dir):
os.mkdir(dir, 0777)
zfobj = zipfile.ZipFile(file)
for name in zfobj.namelist():
if name.endswith('/'):
os.mkdir(os.path.join(dir, name))
else:
outfile = open(os.path.join(dir, name), 'wb')
outfile.write(zfobj.read(name))
outfile.close()
def main():
unzip_file_into_dir(open(sys.argv[1]), sys.argv[2])
if __name__ == '__main__': main()
The unzipped files date and time are not the original ones, but
when the unzipping is done. Is there a way to keep the
original files date and time?
Thanks,
Barto
In this mail,
http://www.mail-archive.com/[email protected]/msg00030.html
Kragen Sitaker explained how to unzip a file in Python
#!/usr/local/bin/python
# learn how to use zipfile module
import sys, zipfile, os, os.path
def unzip_file_into_dir(file, dir):
os.mkdir(dir, 0777)
zfobj = zipfile.ZipFile(file)
for name in zfobj.namelist():
if name.endswith('/'):
os.mkdir(os.path.join(dir, name))
else:
outfile = open(os.path.join(dir, name), 'wb')
outfile.write(zfobj.read(name))
outfile.close()
def main():
unzip_file_into_dir(open(sys.argv[1]), sys.argv[2])
if __name__ == '__main__': main()
The unzipped files date and time are not the original ones, but
when the unzipping is done. Is there a way to keep the
original files date and time?
Thanks,
Barto