如下所示:

source = ['C:\\Users\\admin\\Desktop\\pythonLearning']
target_dir = 'C:\\Users\\admin\\Desktop'
print(time.strftime('%Y%m%d%H%M%S'))
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip'
if not os.path.exists(target_dir):
os.mkdir(target_dir)
zip_command = 'HaoZipC a {0} {1}'.format(target, ' '.join(source))
type = sys.getfilesystemencoding()
print('类型为:', type)
print('Zip command is:')
print(zip_command)
print('Running:')
result = os.system(zip_command)
if result == 0:
print('Successful backup to', target)
else:
print('Backup FAILED')