繁体   English   中英

Python-2.7 zip错误:无效的命令参数(不支持短选项'/')

[英]Python-2.7 zip error: Invalid command arguments (short option '/' not supported)

我正在阅读Byte的Python ,其中包含有关如何编写脚本来压缩文件的内容。 我已经检查了我的代码几次,但仍然找不到错误所在。 我想知道我的代码出了什么问题。顺便说一句,我正在使用Mac,谢谢。

import os
import time
source=[r'/Users/username/Desktop/test.txt']
target_dir=r'/Users/username/Desktop/backup'
target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'
print target
zip_command="zip -qr'%s'%s"%(target,''.join(source))
if os.system(zip_command)==0:
    print 'successful backup to',target
else:
    print 'backup failed'
  • zip错误:无效的命令参数(不支持短选项'/')备份失败

您的zip参数中缺少空格。 您看到的错误是由于将路径解释为选项列表而引起的,因为您具有:

zip -qr/Users/username/Desktop/test.txt

...代替:

zip -qr /Users/username/Desktop/test.txt

替换此行:

zip_command="zip -qr'%s'%s"%(target,''.join(source))

...这样:

zip_command="zip -qr '%s' %s"%(target,''.join(source))

暂无
暂无

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

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