0
0 комментариев

Python 3.7

MacOS X

Вот так  не работает (zipwrite)

import os
import time
import zipfile
 source = ["'/Users/user/Desktop'", "'/Users/user/Documents'"]
target_dir = '/Users/user/Downloads/Backups'
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)
    print('mkdir done')
comment = input('Введите заметку для резервной копии - ')
if len(comment) == 0:
    target = today + os.sep + now + '.zip'
else:
    target = today + os.sep + now + '_' + comment.replace(' ','_') + '.zip'
z = zipfile.ZipFile(target, 'w')
def zipwrite(*directories):
    for dir1 in directories:
        for root, dirs, files in os.walk(dir1):
            for file in files:
               z.write(os.path.join(root,file))
zipwrite(','.join(source))
z.close()
z.printdir()

А так работает:

import os
import time
import zipfile
 source = ["'/Users/user/Desktop'", "'/Users/user/Documents'"]
target_dir = '/Users/user/Downloads/Backups'
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)
    print('mkdir done')
comment = input('Введите заметку для резервной копии - ')
if len(comment) == 0:
    target = today + os.sep + now + '.zip'
else:
    target = today + os.sep + now + '_' + comment.replace(' ','_') + '.zip'
z = zipfile.ZipFile(target, 'w')
def zipwrite(*directories):
    for dir1 in directories:
        for root, dirs, files in os.walk(dir1):
            for file in files:
               z.write(os.path.join(root,file))
zipwrite('/Users/user/Desktop','/Users/user/Documents')
z.close()
z.printdir()

Не могу понять, что не так?

Asked question
Добавить комментарий