import os
import time
source = r'C:\Users\zs\Desktop'
target_dir = r'F:\backup'
target = os.path.join(target_dir,time.strftime('%Y%m%d%H%M%S') + '.zip')
zip_command = "zip -qrm %s %s" % (target, source)
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
print 'Backup failed'
先贴上代码
在这个之前,需要先给windows安装zip,unzip命令
http://stahlforce.com/dev/index.php?tool=zipunzip
放在C:\Windows\System32