A
A
Artem4412020-05-18 13:19:22
Python
Artem441, 2020-05-18 13:19:22

The code for creating a backup copy in Python does not work according to the book "A byte of Python"?

Good afternoon!
Similar question to Why doesn't this python code work? but unfortunately I didn't find the answer there.

There is a code:

import os
import time


# 1. Файлы и каталоги, которые необходимо скопировать, собираются в список
source= ['C:\\Users\\Инглишточка']
# заметьте, что для имен, содержащих пробелы, необходимо использовать
# двойные кавычки внутри строки

# 2. Резервные копии должны храниться в основном каталоге резерва
target_dir = '"C:\\пайтон\\резервная копия"'

# 3. файлы помещаются в zip архив 
# 4. именем для zip-архива служит текущая дата и время

target = target_dir + os.sep + time.strftime("%Y%m%d%H%M%S") + ".zip"

# 5. используем команду "zip" для помещения файлов в zip-архив 
zip_command = "7z a -tzip -ssw -mx1 -r0 {0} {1}".format(target, " ".join(source))

# запускаем создание резервной копии
print(zip_command)

if os.system(zip_command) == 0:
  print(" резервная копия успешно создана в", target)
else:
  print(" создание резервной копии не удалось")


on the command line, the given command: "7z a -tzip -ssw -mx1 -r0 "C:\python\backup"\20200518151629.zip C:\Users\Englishtochka" works, but not in python. Writes the following:
7z a -tzip -ssw -mx1 -r0 "C:\пайтон\резервная копия"\20200518151629.zip C:\Users\Инглишточка
"7z" ■■ ■■ ■■■७■■■ ■■■ ■■■譥■
■■■■■■■■, ■ᯮ■■塞■■ ■ணࠬ■■■ ■■■ ■■■■■■ 䠩■■■.
 создание резервной копии не удалось


Please tell me what is the problem.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem441, 2020-05-18
@Artem441

Accidentally added 7-Zip to "PATH" twice, deleted one and it worked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question