源码:
import zipfile
import os
import time
source_dir = os.listdir(os.getcwd())
target=time.strftime('%Y%m%d%H%M%S') + '.zip'
myZipFile = zipfile.ZipFile(target,'w')
for root,dirs,files in os.walk(source_dir):
for vfileName in files:
fileName = os.path.join(root,vfileName)
myZipFile.write( fileName, fileName, zipfile.ZIP_DEFLATED )
print ( myZipFile.printdir() ) #print all files in zhe zip file,
myZipFile.close()
提示错误:
Traceback (most recent call last):
File "C:\Users\月\Desktop\Test\yasuo.py", line 9, in <module>
for root,dirs,files in os.walk(source_dir):
File "C:\Python33\lib\os.py", line 404, in walk
names = listdir(top)
TypeError: illegal type for path parameter
相关分类