为什么我的Python程序无法正常运行?它可以运行,但不能得到我想要的结果

时间:2015-04-21 00:38:08

标签: python python-3.x

程序的功能是压缩两个文件夹,然后将它们保存到一个文件夹中。该程序可以运行但我收到的错误信息完全如下:

C:\Python34\python.exe D:/Python/backup_ver1.py
'zip' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���

Failed backup

是的,就像你看到的那样。我无法从中获得更多信息。

代码如下:

import os
import time
source = ['E:\\source1','E:\\source2']
target_dir = 'E:\\target'
target = target_dir + os.sep + time.strftime("%Y%m%d%H%M%S") +'.zip'
zip_command = 'zip -qr {0} {1}'.format(target,' '.join(source))

if os.system(zip_command) == 0:
    print("Successful bakup to",target)
else:
    print("Failed backup")

我有" source1"," source2"和"目标"在我的电脑里。

1 个答案:

答案 0 :(得分:0)

我在我的系统上使用7zip,所以我的语法与你的语法略有不同。 试试这个:

import os
import time
source = ['d:\\source1','d:\\source2']
target_dir = 'd:\\target'
target = target_dir + os.sep + time.strftime("%Y%m%d%H%M%S") +'.zip'
zip_command = '"C:\\Program Files\\7-Zip\\7z.exe" a {0} {1}'.format(target,' '.join(source))
if os.system(zip_command) == 0:
    print("Successful bakup to",target)
else:
    print("Failed backup")
相关问题