/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
zip_file_example/zip_file_example.py
55 строк
1 KB
gil9red
Refactoring. Using black code style
25 июн 2023, 15:50
25 июн 2023, 15:50
6a18ae5
Код
Авторство
О чём код?
__author__ = "ipetrash" import os import sys import zipfile if __name__ == "__main__": print("Commands: read, readfile and write") command = input("Command: ") if command == "read": path = input("Archive: ") if not os.path.exists(path): print("File %s not exist!" % path) sys.exit(1) with zipfile.ZipFile(path) as zf: for file_info in zf.infolist(): print(file_info.filename) # zf.printdir() elif command == "readfile": path = input("Archive: ") if not os.path.exists(path): print("File %s not exist!" % path) sys.exit(1) with zipfile.ZipFile(path) as zf: for file_info in zf.infolist(): print(file_info.filename) print() path = input("Name the file in the archive: ") password = input("Password: ") context = zf.read(path, password) print("Context:\n%s" % context.decode()) elif command == "write": name = input("Name archive: ") dir = input("Dir: ") path = os.path.join(dir, name + ".zip") with zipfile.ZipFile(path, mode="w") as zf: print(" Archive: " + path) while True: file_name = input(" add the file: ") if not file_name: break zf.write(file_name) else: print("Unknown command!") sys.exit(1)