![]() |
A program for backing up documents (doesnt work(code is inside)) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: A program for backing up documents (doesnt work(code is inside)) (/thread-16683.html) |
A program for backing up documents (doesnt work(code is inside)) - Richard_SS - Mar-10-2019 The programm should create a backup of selected folder into a folder with a name as current data, and backed up archive should be named as current time. When running a programm im getting a following error: "zip error: Nothing to do! (D://Backup/20190310/165535.zipC://justfolder C://justfolder2.zip)" What am i doing wrong? p.s. im not native english speaker, so, dont ,please, scold me for mistakes, if there are some :D Here is the code of program: import os import time source = ['"C://justfolder "','C://justfolder2'] target_dir = 'D://Backup' today = target_dir + os.sep + time.strftime('%Y%m%d') now = time.strftime('%H%M%S') if not os.path.exists(today): os.mkdir(today) #make directory print('Successfully created directory', today) else: print("Already exists") target = today + os.sep + now + '.zip' zip_command = "zip -r {0}{1}". format(target,''.join(source)) if os.system(zip_command) == 0 : print('Successful backup to', target) else: print('Backup Failed') RE: A program for backing up documents (doesnt work(code is inside)) - Larz60+ - Mar-10-2019 This is much better done using pathlib Please give step details of what you want to do like:
RE: A program for backing up documents (doesnt work(code is inside)) - Richard_SS - Mar-10-2019 (Mar-10-2019, 02:21 PM)Larz60+ Wrote: This is much better done using pathlib What can cause an "zip error: Nothing to do! " error? RE: A program for backing up documents (doesnt work(code is inside)) - woooee - Mar-10-2019 You can use the builtin zipfile https://www.tutorialspoint.com/How-to-create-a-zip-file-using-Python but if you are backing up directory(s) use tarfile https://www.tutorialspoint.com/How-to-create-a-tar-file-using-Python RE: A program for backing up documents (doesnt work(code is inside)) - heiner55 - Jun-05-2019 With some tiny changes, your program runs well. #!/usr/bin/python3 import os import time source = ['"C:/justfolder "','C:/justfolder2'] target_dir = 'D:/Backup' today = target_dir + os.sep + time.strftime('%Y%m%d') now = time.strftime('%H%M%S') . if not os.path.exists(today): os.mkdir(today) #make directory print('Successfully created directory', today) else: print("Already exists") . target = today + os.sep + now + '.zip' . zip_command = "zip -r {0} {1}". format(target,' '.join(source)) print(zip_command) if os.system(zip_command) == 0 : print('Successful backup to', target) else: print('Backup Failed') |