Skip to content
Advertisement

create zip of complete directory using zipfile python module

zip = zipfile.ZipFile(destination+ff_name,"w")
            zip.write(source)
            zip.close()

Above is the code that I am using, and here “source” is the path of the directory. But when I run this code it just zips the source folder and not the files and and folders contained in it. I want it to compress the source folder recursively. Using tarfile module I can do this without passing any additional information.

Advertisement

Answer

The standard os.path.walk() function will likely be of great use for this.

Alternatively, reading the tarfile module to see how it does its work will certainly be of benefit. Indeed, looking at how pieces of the standard library were written was an invaluable part of my learning Python.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement