D
D
DINISLAM Muteshev2021-01-02 10:50:32
Python
DINISLAM Muteshev, 2021-01-02 10:50:32

What if zip is not an internal or external command?

import os
import time
source = ['C:\\python']
target_dir = '"E:\\program files"'
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip'
zip_command = "zip -qr {0} {1}".format(target, ' '.join(source))
print(zip_command)
if os.system(zip_command) == 0:
    print('Резервная копия успешно создана в', target)
else:
    print('Создание резервной копии НЕ УДАЛОСЬ')


throws an error:
"zip" is not recognized as an internal or external
command, operable program or batch file.
Backup Failed

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dr. Bacon, 2021-01-02
@bacon

Your Windows does not know about zip, install it or write it in the path, or even better, read about the module https://docs.python.org/3/library/zipfile.html and use it, and not an external program via os.system

H
Hanneman, 2021-01-02
@Hanneman

Your system has no idea what a zip executable is. Or the path to it is not specified in the PATH environment variable.
Hence the way out: install zip, and if installed, then either add the path to it in the PATH environment variable, or specify the full path to the executable zip file in your script.

A
alekssamos, 2022-01-03
@alekssamos

Make via shutil.make_archive

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question