python入门问题,windows下用python 写调用rar备份文件夹失败,!求指教
import os import time source = [r'C:test'] target_dir = [r'D:test'] today = target_dir + time.strftime('%Y%m%d') now = time.strftime('%H%M%S') target = today + os.sep + now + '.zip' zip_command = " rar a '%s' %s" % (target, ' '.join(source)) if os.system(zip_command) == 0: print 'Successful backup to', target else: print 'Backup FAILED' RAR 4.20 版权所有 (c) 1993-2012 Alexander Roshal 9 Jun 2012 Trial version Type RAR -? for help 评估版。请注册。 Backup FAILED 无法创建 'D:test20140914193220.zip' 文件名、目录名或卷标语法不正确。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
zip_command = " rar a '%s' %s" % (target, ' '.join(source))
试试改成
import os
import time
source = 'C:\Intel\Logs\23.txt'
target_dir = 'e:\backup\'
today = target_dir + time.strftime('%Y%m%d')
#print (today)
now = time.strftime('%H%M%S')
comment = input('Enger a comment--->::::')
print (comment)
if len(comment) ==0:
target = today + os.sep + now + '.zip'
#print (target)
else:
target = today + os.sep + now + '_' + comment.replace(' ', '_') + '.zip'
#rint (target)
if not os.path.exists(today):
os.mkdir(today)
print ("Sucessful mkdir directory")
#print (os.sep)
#target = today + os.sep + now + '.zip'
#print (target)
zip_command = "makecab %s %s" % (source,target)
#print (zip_command)
if os.system(zip_command) == 0:
print ('Sucessful backup to' ,target)
else:
print ('Backup faild!')
import os
import time
source = 'C:\test'
target_dir = 'D:\test'
today = target_dir + os.sep + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
target = today + '_' + now + '.zip'
zip_command = "rar a %s %s" %(target, source)
if os.system(zip_command) == 0:
print ("Successful backup to " + target)
else:
print ("Backup FAILED")
today = target_dir + time.strftime('%Y%m')
TypeError: can only concatenate list (not "str") to list
C:\test
你先创建一下test20140914目录,再输出压缩文件试试。
这个问题其实跟python没多大关系。