Solved! Go to Solution.
import zipfile zip = zipfile.ZipFile(r'c:\my.zip') zip.extractall(r'c:\output')
import zipfile zip = zipfile.ZipFile(r'c:\my.zip') zip.extractall(r'c:\output')
def zip_directory_to_zipfile(directory, out_zipfile): out_zip = zipfile.ZipFile(out_zipfile, 'w') for (dirpath, dirnames, filenames) in os.walk(directory): for file in filenames: path_in_zip = os.path.join(os.path.relpath(dirpath, lib_dir), file) if os.path.split(path_in_zip)[0] == ".": path_in_zip = os.path.split(path_in_zip)[1] out_zip.write(os.path.join(dirpath, file), path_in_zip)
I think you are onto somthing, but I need a little help integrating it into the arcpy module. What would it be like if we know that the dirpath is the arcpy.env.workspace is the current one. Then we want to make everything in that dirpath zipped up. Would it make the script shorter somehow?
def zip_directory_to_zipfile(out_zipfile): out_zip = zipfile.ZipFile(out_zipfile, 'w') for (dirpath, dirnames, filenames) in os.walk(arcpy.env.workspace): for file in filenames: path_in_zip = os.path.join(os.path.relpath(dirpath, lib_dir), file) if os.path.split(path_in_zip)[0] == ".": path_in_zip = os.path.split(path_in_zip)[1] out_zip.write(os.path.join(dirpath, file), path_in_zip)
out_zip = zipfile.ZipFile(out_zipfile, 'w', zipfile.ZIP_DEFLATED)
That fixed it. Much thanks.
New problem.
Any way to set it up so that it creates a split zip file of 5MB max size.
i.e. the original file is just over 10.7MB using the code above but my email server will only allow a 10MB file. If I can split the file into a split zip of 5MB parts I can send it as two emails.