Recursive zipping of Directories in Windows

Jandre jandre_balt at yahoo.co.uk
Thu Feb 1 15:13:14 EST 2007


Hi

I am a python novice and I am trying to write a python script (most of
the code is borrowed) to Zip a directory containing some other
directories and files. The script zips all the files fine but when it
tries to zip one of the directories it fails with the following
error:
"IOError: [Errno 13] Permission denied: 'c:\\aaa\\temp'"

The script I am using is:

import zipfile, os

def toZip( directory, zipFile ):
    """Sample for storing directory to a ZipFile"""
    z = zipfile.ZipFile(
        zipFile, 'w', compression=zipfile.ZIP_DEFLATED
    )
    def walker( zip, directory, files, root=directory ):
        for file in files:
            file = os.path.join( directory, file )
            # yes, the +1 is hacky...
            archiveName = file[len(os.path.commonprefix( (root,
file) ))+1:]
            zip.write( file, archiveName, zipfile.ZIP_DEFLATED )
            print file
    os.path.walk( directory, walker, z  )
    z.close()
    return zipFile


if __name__ == "__main__":
    toZip( 'c:\\aaa', 'c:\\aaa\\test.zip' )

I have tried to set the permissions on the folder, but when I check
the directory permissions it is set back to "Read Only"

Any suggestions?

Thanks
Johan Balt




More information about the Python-list mailing list