Python Forum

Full Version: Create ZIP file not working using ZipFile?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I'm trying to zip 1 big txt file before upload it (so insted of 22MB it will be ~ 2MB )
but the file created is 22MB and it's corrupted
the Output fie is working and readable - no problem there

OutputFile = 'D:\\Sync\\Sync\\Upload\\CutLogData1.txt'
zipObj = ZipFile('D:\\Sync\\Sync\\Upload\\ZIPData.zip', 'w')
 with open(OutputFile, 'w') as f:
        for line in Lines:
            count += 1
            if StartLine <= count <= EndLine:
                f.write(line.strip() + "\r\n")
           # OutputFile.write(line.strip() + "\r\n")
    zipObj.write(OutputFile)
    zipObj.close()
    f.close()
what did I do wrong ?

I have also try to do this
 
ZipLocation = ('D:\\Sync\\Sync\\Upload\\CanBusData.zip')
    with ZipFile(ZipLocation, 'w') as zipObj:
        zipObj.write(OutputFile)
but the file is the same as the txt ~ 22MB
how could it be ?
and also it zipp me the all path of the file - meaning I have 4 folders before I get into the txt file in the zip
why? how can I make it only the file itself?

Thanks ,
very stupid but you need to tell him to comprase the files....

To add compression, the zlib module is required. If zlib is available, you can set the compression mode for individual files or for the archive as a whole using zipfile.ZIP_DEFLATED. The default compression mode is zipfile.ZIP_STORED.
solution if someone else need to do this