该脚本当前在当前工作目录中创建一个zip文件夹,并使用当前登录的用户文件填充它(例如“Documents and Settings \ Owner *”。但是,我想用密码保护zip文件夹;我已经在这里查看了可行的回复,但他们要么是旧帖子,要么是发布问题的人未经证实。
那么,我如何用密码保护已在python中创建的zip文件?
我当前的代码;
import os, zipfile, getpass, sys
try:
user= getpass.getuser()
print " [*] Creating a zip-folder in current working directory...\r"
zf = zipfile.ZipFile(user + ".zip", "w", zipfile.ZIP_DEFLATED)
sys.__stdout__
directory = "C:\\Documents and Settings\\Owner"
print " [*] Created successfully..."
print" [*] Attempting to copy files...\r"
for dirname, subdirs, files in os.walk(directory):
sys.stdout.write(" [*] Now copying files...\r")
if "Local Settings" in files:
continue
zf.write(dirname)
for filename in files:
if "NTUSER" in filename:
continue
elif "ntuser" in filename:
continue
elif user + ".zip" in filename:
continue
elif "UsrClass" in filename:
continue
zf.write(os.path.join(dirname, filename))
print ' [*] Completed copying files to zip-file...'
except IOError as e:
print ' [-] ' + e
except KeyboardInterrupt:
print ' [-] Cancelling current operation'
sys.exit(0)
zf.close()