zipping folders using python
hello all,
im really new to python. please help me out with this i'm trying to create a python script that will zip a folder. In my red hat PC, in /usr/local/testlogs/, there will be be few folders. i want to zip all the folder's , NOT as one zip file, but as multiple zip files. please help me out!! |
Please show us what you have got already and where you have problems with your code.
|
#
import os import zipfile path = '/usr/local/testlogs/test2/*' def zipdir(path, zip): for root, dirs, files in os.walk(path): for file in files: zip.write(os.path.join(root, file)) for directories in glob.glob(path) : zipf = zipfile.ZipFile('%s.zip'%directory, 'w') zipdir(path, zipf) zipf.close() # |
When posting Python code it is mandatory to use code-tags (see my signature for explanation), so that the indentation is preserved. Not indented Python code is unreadable.
|
hi,
sorry about that. i have tried really hard to get this working and below is my latest script. im not sure why its not creating separate zip files. It is adding all the folders into 1 zip file Code:
def zip_folder(folder_path, output_path): |
another thing is...i also can figureout a way on how get the zipfiles to be named the same the folder it will zip
|
All times are GMT -5. The time now is 01:52 AM. |