Last active
February 21, 2024 22:31
-
-
Save farzadhallaji/2e5fd24697aa88323f45608a3080e597 to your computer and use it in GitHub Desktop.
zip folder for myself
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zipfile | |
import tarfile | |
import os | |
def zip_folder(folder_path, zip_filename): | |
with zipfile.ZipFile(zip_filename, 'w') as zipf: | |
for foldername, subfolders, filenames in os.walk(folder_path): | |
for filename in filenames: | |
file_path = os.path.join(foldername, filename) | |
arcname = os.path.relpath(file_path, folder_path) | |
zipf.write(file_path, arcname) | |
def unzip_tar_gz(file_path, extract_to='.'): | |
with tarfile.open(file_path, 'r:gz') as tar: | |
tar.extractall(path=extract_to) | |
print(f'Files extracted to {os.path.abspath(extract_to)}') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment