Compress and extract folders in Python

The module 'tarfile' provides the functionality to compress and extract folders.

To create compressed file,

import tarfile
with'folder.tar.gz', "w:gz") as tar:

Where 'folder' is the name of the folder that need to be compressed.

To extract compressed file,

import tarfile
t ='folder.tar.gz', 'r')

Where 'folder.tar.gz' is the file that need to be extracted.


Leave a Reply

Your email address will not be published. Required fields are marked *