Zip Files ?
Verfasst: Mittwoch 25. Februar 2015, 11:20
Folgendes script führt bei mir zu keinem Ergebnis?
Warum?
Code: Alles auswählen
import zipfile
import os,stat, sys, arcpy
from cStringIO import StringIO
def createZip(path):
def walktree (top = ".", depthfirst = True):
names = os.listdir(top)
if not depthfirst:
yield top, names
for name in names:
try:
st = os.lstat(os.path.join(top, name))
except os.error:
continue
if stat.S_ISDIR(st.st_mode):
for (newtop, children) in walktree (os.path.join(top, name),
depthfirst):
yield newtop, children
if depthfirst:
yield top, names
list=[]
for (basepath, children) in walktree(path,False):
for child in children:
f=os.path.join(basepath,child)
if os.path.isfile(f):
f = f.encode(sys.getfilesystemencoding())
list.append( f )
f=StringIO()
file = zipfile.ZipFile(f, "w")
for fname in list:
nfname=os.path.join(os.path.basename(path),fname[len(path)+1:])
file.write(fname, nfname , zipfile.ZIP_DEFLATED)
file.close()
f.seek(0)
return f
path = r"R:\Karto\Bierer2015\Webkarten"
outZipFile = r"R:\Karto\Bierer2015\Datenbank_RP"
createZip(path)