I'm a newbie programmer and I started reading A Byte of Python. The first problem in the book is a program that needs to solve the following problem: "Create a backup of all my important files". This is the design of the program:
The files and directories to be backed up are specified in a list.
The backup must be stored in a main backup directory.
The files are backed up into a zip file.
The name of the zip archive is the current date and time.
This is the implementation:
import os
import time
source = ['/Users/swa/notes']
target_dir = '/Users/swa/backup'
target = target_dir + os.sep + \
time.strftime('%Y%m%d%H%M%S') + '.zip'
if not os.path.exists(target_dir):
os.mkdir(target_dir)
zip_command = "zip -r {0} {1}".format(target,
' '.join(source))
print "Zip command is:"
print zip_command
print "Running:"
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
print 'Backup FAILED'
I don't understand the
target = target_dir + os.sep + \
time.strftime('%Y%m%d%H%M%S') + '.zip'
if not os.path.exists(target_dir):
os.mkdir(target_dir)
zip_command = "zip -r {0} {1}".format(target,
' '.join(source))
part. I have searched python documentation to understand what os.sep and os.mkdir and time.strftime ... is but if someone could explain it all to me I would be very grateful