2013-07-31 75 views
0

我試圖在Windows7上的Python 2.7中執行下面的代碼。代碼的目的是根據給定的命名模式從指定文件夾恢復到指定文件夾。備份程序 - Python

但是,我不能得到它的工作。輸出一直是'備份失敗'。

請告訴我如何解決這個問題,讓代碼工作。

謝謝。

代碼:

backup_ver1.py 

import os 
import time 
import sys 

sys.path.append('C:\Python27\GnuWin32\bin') 
source = 'C:\New' 
target_dir = 'E:\Backup' 
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip' 
zip_command = "zip -qr {0} {1}".format(target,''.join(source)) 
print('This is a program for backing up files') 
print(zip_command) 

if os.system(zip_command)==0: 
print('Successful backup to', target) 
else: 
print('Backup FAILED') 
+1

您已經打印zip命令;你有沒有嘗試完全複製它並從命令行執行它?然後你會看到它輸出的錯誤。 – poke

回答

1

看看逃避\的幫助: -

source = 'C:\\New' 
target_dir = 'E:\\Backup' 
+0

或者使用「raw」字符串文字:'source = r'C:\ New'' – Blckknght

+0

嘗試過。它不起作用。 – Learner12

+0

嘗試在我的系統上,但它顯示控制檯上的錯誤。您在控制檯上看不到任何錯誤? – Himanshu