473,395 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

zipfile module

LC
Hi,

I'm having a problem using the zipfile module in Windows 2000 sp4. When I
use it to zip a small file it works fine, but large file doesnt. Here's the
error msg i get...
---------------------------------------------------------------------
dynamite4_db_archive.py", line 45, in ?
file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
File "C:\Python22\lib\zipfile.py", line 426, in write
zinfo.file_size))
OverflowError: long int too large to convert to int
---------------------------------------------------------------------
I've read a couple of problems with this module with long int, and it says
it's a know problem in Python earlier than 2.3
So I upgraded to 2.3 and i'm still getting the error msg. I'm not proficient
at python so I'm not sure what to do at this point. The file I'm currently
trying to zip is about 2.5GB.

Here's my code that's causing the error...
----------------------------------------------------------------------
currentDirFiles = os.listdir(mydir) #list log file in dir
os.mkdir(todays_dir)

for item in currentDirFiles: #find the file with the date from 7 days ago

file_to_zip = mydir + item
destination = todays_dir + str('/') + item + str('_') + todays_date +
str('.zip')

print "\n" + file_to_zip + "\n" + destination

file = zipfile.ZipFile(destination, "w")

for name in glob.glob(file_to_zip):
file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)

file.close()
---------------------------------------------------------------------

Any help would be appreciated. TIA

LC
Jul 18 '05 #1
1 2900

lco> dynamite4_db_archive.py", line 45, in ?
lco> file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
lco> File "C:\Python22\lib\zipfile.py", line 426, in write
lco> zinfo.file_size))
lco> OverflowError: long int too large to convert to int

...

lco> for name in glob.glob(file_to_zip):
lco> file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)

How about you write the file in chunks? I'm not familiar with the zipfile
module, but it looks like writestr will do the job for you. My guess is
something like

...
file = zipfile.ZipFile(destination, "w", zipfile.ZIP_DEFLATE)
for name in glob.glob(file_to_zip):
...
f = open(name)
data = f.read(8192)
while data:
file.writestr(os.path.basename(name), data)
data = f.read(8192)
f.close()
file.close()

might do the trick. (The zipfile module's interface to writing data looks a
bit odd to me.)

Skip

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: stewart.midwinter | last post by:
I've been experimenting with the python zipfile module, and have run into a snag. I'm able to create a new zipfile with the module's ZipFile class and add files to it. After closing the file,...
5
by: Waguy | last post by:
Hi all, I am new to python and want to create a process to unzip large numbers of zip files I get from a SOAP application. The files all have a ZIP extention and can be unzipped using WinZip. ...
11
by: Hari Sekhon | last post by:
I do import zipfile zip=zipfile.ZipFile('d:\somepath\cdimage.zip') zip.namelist() then either of the two: A) file('someimage.iso','w').write(zip.read('someimage.iso'))
1
by: Ritesh Raj Sarraf | last post by:
Hi, I've got a problem here. def compress_the_file(zip_file_name, files_to_compress, sSourceDir): """ Condenses all the files into one single file for easy transfer """ try:
5
by: OriginalBrownster | last post by:
This will probably sound like a very dumb question. I am trying to zip some files within a directory. I want to zip all the files within a directory called "temp" and have the zip archive...
8
by: =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B | last post by:
I made a C/S network program, the client receive the zip file from the server, and read the data into a variable. how could I process the zipfile directly without saving it into file. In the...
3
by: towers | last post by:
Hi I'm probably doing something stupid but I've run into a problem whereby I'm trying to add a csv file to a zip archive - see example code below. The csv just has several rows with carriage...
3
by: Larry Bates | last post by:
I'm trying to learn about subclassing new style classes and the first project I went to do needs to subclass zipfile to add some methods. Why does this: import zipfile class...
5
by: Neil Crighton | last post by:
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for extracted text-encoded files, removing all instances...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.