0

Im trying to execute the following code in Python 2.7 on Windows7. The purpose of the code is to take back up from the specified folder to a specified folder as per the naming pattern given.

However, Im not able to get it work. The output has always been 'Backup Failed'.

Please advise on how I get resolve this to get the code working.

Thanks.

Code :

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
  • 1
    You already print the zip command; have you tried copying it exactly and executing it from the command line? Then you will see the error it outputs. Commented Jul 31, 2013 at 10:56

1 Answer 1

1

See if escaping the \'s helps :-

source = 'C:\\New'
target_dir = 'E:\\Backup'
Sign up to request clarification or add additional context in comments.

10 Comments

Or use "raw" string literals: source = r'C:\New'
Tried on my system but it shows the errors on the console. You don't see any errors on the console?
I was trying with IDLE. I tried executing from Command Prompt now, I get the following error: " 'zip" is not recognised as an internal or external command, operable program or batch file". Any idea whats the way out of this - where am I wrong?
Add the path to the zip program to the environment variable
I thought this line does the job : "sys.path.append('C:\Python27\GnuWin32\bin')". Is it not?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.