Answer the question
In order to leave comments, you need to log in
Hello, can you rate the code?
This is one of my first codes that I was not asked to do at school, but which is really needed and useful for something.
And I wanted to know how well I coped with my task . The task
was
as follows:
directory) and create an archive from it (To the specified directory)
2) It should be able to be used by people who do not know the language
3) It should be readable
And here is the code itself:
import shutil
import time
from datetime import datetime
# Настройки
t = 10
# ↑↑↑ Интервал между бэкапами в минутах ↑↑↑
directory_copy = 'C:\\Users\\MinuteX\\Desktop\\Copy'
# ↑↑↑ Вписать директория откуда копировать папку
directory = 'C:\\Users\\MinuteX\\Downloads\\Paste'
# ↑↑↑ Вписать директорию куда будут копироватся файлы
# ||| ВАЖНО!!! ВСЕ СЛЕШЫ В ДИРЕКТОРИЯХ ДОЛЖНЫ БЫТЬ ДВОЙНЫМИ ↑↑↑
i = 0
t *= 60
while True:
dt = datetime.today().strftime("%Y-%m-%d-%H.%M.%S")
name = f"backup_{i}_{dt}"
direct = f"{directory}\\{name}"
shutil.make_archive(
direct,
'zip',
directory_copy
)
print("Generate new backup: " + name)
i += 1
time.sleep(t)
Answer the question
In order to leave comments, you need to log in
directory_copy = 'C:\\Users\\MinuteX\\Desktop\\Copy'
direct = f"{directory}\\{name}"
print("Generate new backup: " + name)
print(f"Generate new backup: {name}")
t = 10
# ↑↑↑ Интервал между бэкапами в минутах ↑↑↑
print("Generate new backup: " + name)
What is there to evaluate? It's a little wider than Halloween.
If you remove the extra empty lines and captain's comments, then the code will be one short bunch.
Instead of unnecessary comments (by the way, it's better to use only English)
, let's give normal, sane names to variables.
t -> backup_interval
directory_copy -> source_directory
directory -> target_directory
dt -> current_time
What is this?
i ->
t ->
name ->
direct ->
You have to read the entire script to understand. With normal names of variables and functions, the code is read an order of magnitude faster and easier.
Less comments (for such a program) and empty space, and everything is ok.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question