Python Forum
[solved] compressing files with python.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] compressing files with python.
#1
Question 
Hi everyone,

I'm looking for Pytonic readable way to compress files.

I've found https://docs.python.org/3/library/gzip.html

with which I came out with

import gzip
with open('/somewhere/aFile.whatever', 'rb') as ToBeCompressed:
    ReadedBytes = ToBeCompressed.read()

with gzip.open('/somewhere/destination.gz', 'wb') as f:
    f.write(ReadedBytes )
so it work, but within the gz , the file lost it's filename is became 'destination/destination'

Any ideas how to keep or set the filename ?

Or any other method to compress and save ?

Thanks.
[Image: NfRQr9R.jpg]
Reply
#2
Never mind I found an easy way -->

https://docs.python.org/3/library/tarfile.html
[Image: NfRQr9R.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help replacing word in Mutiple files. (SOLVED) mm309d 0 844 Mar-21-2023, 03:43 AM
Last Post: mm309d
  Delete empty text files [SOLVED] AlphaInc 5 1,583 Jul-09-2022, 02:15 PM
Last Post: DeaD_EyE
  Sorting and Merging text-files [SOLVED] AlphaInc 10 4,921 Aug-20-2021, 05:42 PM
Last Post: snippsat
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,171 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  compressing a file Skaperen 5 2,587 Jun-05-2021, 11:38 PM
Last Post: Skaperen
Question (solved) open multiple libre office files in libre office lucky67 5 3,366 May-29-2021, 04:54 PM
Last Post: lucky67
  Looping through music files (SOLVED) ebolisa 0 2,514 Jul-13-2019, 06:16 PM
Last Post: ebolisa
  Running a python tool transforming xml files into epub files silfer 7 5,444 May-10-2018, 03:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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