Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python zip folder

import shutil
shutil.make_archive(output_filename, 'zip', dir_name)
Comment

python zip folder

import os
import zipfile

def zip_directory(folder_path, zip_path):
    with zipfile.ZipFile(zip_path, mode='w') as zipf:
        len_dir_path = len(folder_path)
        for root, _, files in os.walk(folder_path):
            for file in files:
                file_path = os.path.join(root, file)
                zipf.write(file_path, file_path[len_dir_path:])
                
zip_directory('C:/FolderToZip', 'C:/Folder.zip')
Comment

python zip folder

#!/usr/bin/env python
import os
import zipfile

def zipdir(path, ziph):
    # ziph is zipfile handle
    for root, dirs, files in os.walk(path):
        for file in files:
            ziph.write(os.path.join(root, file))

if __name__ == '__main__':
    zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
    zipdir('tmp/', zipf)
    zipf.close()
Comment

zip a directory in python

shutil.make_archive(output_filename, 'zip', dir_name)
Comment

PREVIOUS NEXT
Code Example
Python :: isoformat datetime python 
Python :: how to append in dictionary in python 
Python :: keras model save 
Python :: python dictionary comprehensions 
Python :: while loops python 
Python :: python byte like to string 
Python :: remove key from dictionary 
Python :: Python RegEx Split – re.split() 
Python :: python redirect with button click 
Python :: group by list python 
Python :: how to set pandas dataframe as global 
Python :: how to remove an element from dictionary using his value python 
Python :: manage python environment in jupyterlab 
Python :: List comprehension if-else 
Python :: python parse int as string 
Python :: get index of all element in list python 
Python :: django login required 
Python :: python mqtt subscribe code 
Python :: Your WhiteNoise configuration is incompatible with WhiteNoise v4.0 
Python :: Difference between two dates and times in python 
Python :: how to check if a variable holds a class reference in python 
Python :: free download django app for windows 10 
Python :: python tuple and dictionary 
Python :: transform image to rgb python 
Python :: python how to add a string to a list in the middle 
Python :: flask No application found. Either work inside a view function or push an application context 
Python :: obtain items in directory and subdirectories 
Python :: how to add a column with more rows to a dataframe 
Python :: shrink colorbar matplotlib 
Python :: Kivy Python ListView Scrollview with Toggle on off 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =