Python Forum
Create ZIP file not working using ZipFile?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create ZIP file not working using ZipFile?
#1
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 ,
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using zipfile module - finding folders not files darter1010 2 274 Apr-06-2024, 07:22 AM
Last Post: Pedroski55
  Create Choices from .ods file columns cspower 3 605 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,895 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  Use PM4PY and create working file thomaskissas33 0 668 Nov-14-2023, 06:53 AM
Last Post: thomaskissas33
  Create csv file with 4 columns for process mining thomaskissas33 3 757 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  zipfile module error pseudo 3 771 Jun-30-2023, 03:52 PM
Last Post: Gribouillis
  create exe file for linux? korenron 2 983 Mar-22-2023, 01:42 PM
Last Post: korenron
  my first file won't create itself MehHz2526 2 903 Nov-27-2022, 12:58 AM
Last Post: MehHz2526
  Create multiple/single csv file for each sql records mg24 6 1,399 Sep-29-2022, 08:06 AM
Last Post: buran
  [Solved by deanhystad] Create a zip file using zipfile library DZ_Galaxy 2 1,164 Aug-17-2022, 04:57 PM
Last Post: DZ_Galaxy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020