Python Forum
A program for backing up documents (doesnt work(code is inside))
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A program for backing up documents (doesnt work(code is inside))
#1
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')
Reply
#2
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.
Reply
#3
(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?
Reply
#4
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
Reply
#5
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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  im not sure what ive done wrong code doesnt run dgizzly 3 1,334 Nov-16-2022, 03:02 AM
Last Post: deanhystad
  my simple code wont work! help! simon12323121 2 1,990 Sep-05-2021, 09:06 AM
Last Post: naughtyCat
  My code does not work as expected (pygame) rohes_kaugummi 1 1,532 Aug-26-2021, 03:13 PM
Last Post: deanhystad
  I wrote a code but it does not work out as expected chinitayao226 2 1,835 Sep-23-2020, 09:14 PM
Last Post: SnowwyWolf
  It worked now it doesnt...ugh raymond2688 15 5,317 Aug-07-2019, 07:47 PM
Last Post: raymond2688
  Program that, inside a loop, does multiple things. needs to print in a certain way reidmcleod 1 2,639 Feb-19-2019, 02:35 PM
Last Post: marienbad
  Editing excel documents chizz1996 1 2,015 Nov-28-2018, 03:16 PM
Last Post: Larz60+
  Help Me Code This Program NZedMarine 1 2,035 Nov-16-2018, 12:11 AM
Last Post: Larz60+
  My program won't run through the entire code EvanCahill 1 2,214 Jul-26-2018, 03:19 AM
Last Post: ichabod801
  I Can't Get This Sorting Function In This LinkedList Code To Work JayJayOi 10 7,833 Jan-11-2018, 01:14 AM
Last Post: JayJayOi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020