-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (37 loc) · 1.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import datetime
import shutil
import time
path = str(input('Informe o diretorio dos arquivos que seram apagados:'))
listFile = os.listdir(path)
cleaningTime = str(input('Defina a hora de limpeza da pasta (HH:MM):'))
def createFolderBackup():
directory = path
folderName = datetime.datetime.now().strftime('bkp_%d%m%Y')
os.mkdir('{}\{}'.format(directory, folderName))
def moveFile():
folderName = datetime.datetime.now().strftime('bkp_%d%m%Y')
fate = ('{}\{}'.format(path, folderName))
for file in listFile:
if file != folderName:
file = '{}\{}'.format(path, file)
shutil.copy2(file, fate)
def compressFolder():
folderName = datetime.datetime.now().strftime('bkp_%d%m%Y')
fate = ('{}\{}'.format(path, folderName))
shutil.make_archive(fate, 'zip', fate)
shutil.rmtree(fate)
def clearFolder():
folderName = datetime.datetime.now().strftime('bkp_%d%m%Y')
for file in listFile:
if file != folderName:
os.remove('{}\{}'.format(path, file))
while True:
now = datetime.datetime.now().strftime('%H:%M')
if now == cleaningTime:
createFolderBackup()
moveFile()
compressFolder()
clearFolder()
print('############## Limpeza realizada com sucesso ##############')
time.sleep(40)