简体   繁体   English

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

[英]Why my Python program can't run correctly? It can run but don't get the result I want to

The function of the program is to compress two folders and then save them to one folder. 该程序的功能是压缩两个文件夹,然后将它们保存到一个文件夹中。 The program can run but I get an error message exactly as follows: 该程序可以运行,但是我收到的错误消息完全如下:

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

Failed backup

Yes, it's just as you see. 是的,就像您看到的一样。 I can't get more information from that. 我无法从中获得更多信息。

The code is as follow: 代码如下:

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")

I have "source1", "source2" and "target" in my computer. 我的计算机中有“ source1”,“ source2”和“ target”。

I use 7zip on my system, so my syntax is a little different than yours. 我在系统上使用7zip,所以语法与您的语法有些不同。 Try this: 尝试这个:

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM