Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python zip folder and subfolders

import zipfile
import os
import sys

def zipfolder(foldername, target_dir):            
    zipobj = zipfile.ZipFile(foldername + '.zip', 'w', zipfile.ZIP_DEFLATED)
    rootlen = len(target_dir) + 1
    for base, dirs, files in os.walk(target_dir):
        for file in files:
            fn = os.path.join(base, file)
            zipobj.write(fn, fn[rootlen:])

zipfolder('thenameofthezipfile', 'thedirectorytobezipped') #insert your variables here
sys.exit()
Comment

PREVIOUS NEXT
Code Example
Python :: django abstractuser 
Python :: insert data in sqlite database in python 
Python :: download unsplash images python 
Python :: how ro have a incresing variable in python 
Python :: python how to insert values into string 
Python :: django forms date picker 
Python :: how to convert float to string in python 
Python :: python module location 
Python :: python get line of exception 
Python :: get coordinates in xarray 
Python :: python use variable name as variable 
Python :: array sort python 
Python :: make sure it only has letters and numbers python 
Python :: twitter api tutorial python 
Python :: math module in python 
Python :: expand alphabets in python 
Python :: python convert b string to dict 
Python :: permission denied when converting dataframe to csv 
Python :: how to hide tkinter window 
Python :: makemigration django 
Python :: how to find length of list python 
Python :: Aggregate on the entire DataFrame without group 
Python :: list vs tuple python 
Python :: python is instance 
Python :: remove empty string from list python single line 
Python :: stack in python using linked list 
Python :: python print fraction 
Python :: index duplicates python 
Python :: pytorch dill model save 
Python :: stack in python 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =