Reputation: 1
I'm trying to write a code to create backup of files or directory using Python but there is an error : can only concenate list not "str" Here's my code :
import os
import time
# The files or directory which has to be backed up
source = ['"F:\\College Stuffs"']
#The backup must be stored in a target directory
target_dir = ['"E:\\Backup"']
#File will be backed up in a zip file and name will be set to current date
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + target.append('.zip')
# Create the directory if it's not present
if not os.path.exists(target_dir):
os.mkdir(target_dir) #Make the directory
#Use zip command to put files in a zip archive
zip_command = "zip -r {} {}".format(target,''.join(source))
#run the backuo
print "Zip command is : "
print zip_command
print "Running:"
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
print 'Backup FAILED'
Upvotes: 0
Views: 42
Reputation: 39853
You've defined a list
#The backup must be stored in a target directory
target_dir = ['"E:\\Backup"']
while your usage indicates you'd intended to use a str
there:
#The backup must be stored in a target directory
target_dir = '"E:\\Backup"'
Upvotes: 1