Python Forum

Full Version: A program for backing up documents (doesnt work(code is inside))
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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')
This is much better done using pathlib
Please give step details of what you want to do like:
  • copy all files in ...
  • create new dir ...
  • zip contents of ... to ...
I'm not sure what source = ['"C://justfolder "','C://justfolder2'] is supposed to be doing.
(Mar-10-2019, 02:21 PM)Larz60+ Wrote: [ -> ]This is much better done using pathlib
Please give step details of what you want to do like:
  • copy all files in ...
  • create new dir ...
  • zip contents of ... to ...
I'm not sure what source = ['"C://justfolder "','C://justfolder2'] is supposed to be doing.

What can cause an "zip error: Nothing to do! " error?
You can use the builtin zipfile https://www.tutorialspoint.com/How-to-cr...ing-Python but if you are backing up directory(s) use tarfile https://www.tutorialspoint.com/How-to-cr...ing-Python
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')