# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# ErrorPointFinder.py
# Created on: 2016-07-27 09:10:17.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------
import random
from itertools import groupby
import os
import zipfile
'''
path = u"H:\基础数据及工作底图\非涉密成果\县级工作底图成果\第一批工作底图(16个县)"
outpath = u"H:\基础数据及工作底图\非涉密成果\县级工作底图成果\output0"
current_files = os.listdir(path)
for file_name in current_files:
print(file_name)
dirname = path + "\" + file_name + "\DLG"
if not os.path.exists(dirname):
continue
os.mkdir(outpath + "\" + file_name)
filelist = []
for root, dirlist, files in os.walk(dirname):
for filename in files:
filelist.append(os.path.join(root, filename))
#Start to zip file ...
fullzipfilename = outpath + "\"+ file_name + "\DLG.zip"
destZip = zipfile.ZipFile(fullzipfilename, "w")
for eachfile in filelist:
destfile = eachfile[len(dirname):]
print("Zip file %s..." % destfile)
destZip.write(eachfile, destfile)
destZip.close()
#os.mkdir(outpath + "\" + file_name)
'''
path = u"E:\guangxi\output"
current_files = os.listdir(path)
for file_name in current_files:
print(file_name)
fullzipfilename = path + "\" + file_name + "\DLG.zip"
fullunzipdirname = path + "\" + file_name
srcZip = zipfile.ZipFile(fullzipfilename, "r")
for eachfile in srcZip.namelist():
print("Unzip file %s ..." % eachfile)
eachfilename = os.path.normpath(os.path.join(fullunzipdirname, eachfile))
'''
eachdirname = os.path.dirname(eachfilename)
if not os.path.exists(eachdirname):
os.makedirs(eachdirname)
'''
fd=open(eachfilename, "wb")
fd.write(srcZip.read(eachfile))
fd.close()
srcZip.close()