Recursive zipping of Directories in Windows



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

.



Relevant Pages

  • Re: Recursive zipping of Directories in Windows
    ... I am a python novice and I am trying to write a python script (most of ... The script zips all the files fine but when it ... def toZip(directory, zipFile): ... can't handle open files. ...
    (comp.lang.python)
  • simple UnZip
    ... Can someone help me with this script, ... unzips one file from a zipfile, not all files in a zipfile. ... for fzip in zips: ... print fzip," is a zip" ...
    (comp.lang.python)
  • Re: Zipping files
    ... I have come across an error while using zipfile and I can't seem to ... My script needs to be able ... zout = zipfile.ZipFile ... on XP don't have that permission, ...
    (comp.lang.python)
  • Zipping files
    ... I have come across an error while using zipfile and I can't seem to ... My script needs to be able ... zout = zipfile.ZipFile ... print fullpath, "successfully added to", zFullpath ...
    (comp.lang.python)
  • Re: Zip a file programatically
    ... OK, Miyahn, your "unreliable" script works on WinXP SP2 if any ... > ZipFile = FS.BuildPath ... > On Error GoTo 0 ... > Sub SelectItem ...
    (microsoft.public.scripting.vbscript)