-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdelete_file.py
More file actions
78 lines (56 loc) · 1.89 KB
/
Copy pathdelete_file.py
File metadata and controls
78 lines (56 loc) · 1.89 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import threading
import time
global files, number_files, excluding, excluded, stop
files = []
number_files = 0
excluding = 0
excluded = 0
stop = False
def print_run():
while stop == False:
print(f'Escaneando.', end='\r')
time.sleep(1)
print(f' ', end='\r')
print(f'Escaneando..', end='\r')
time.sleep(1)
print(f' ', end='\r')
print(f'Escaneando...', end='\r')
time.sleep(1)
print(f' ', end='\r')
def search_for_files(path, searched_file):
global files, number_files, excluding, stop
for (dirpath, dirnames, filenames) in os.walk(path):
for file in filenames:
if file == searched_file:
files.append({"path": dirpath,
"file": file})
excluding = excluding + 1
number_files = number_files + len(filenames)
stop = True
def confirm_exluding():
global files, excluded
print(f'>Serão excluidos {excluding} arquivos.')
print(f'>Digite "Yes" para confirmar exclusão...')
answer = input()
if answer != 'Yes':
print(f'>Cancelado!')
else:
for file in files:
full_file = file["path"] + '/' + file["file"]
os.remove(full_file)
print(f'>>>Total de arquivos excluído: { full_file }')
excluded = excluded + 1
print(f'>>>Arquivos excluídos: { excluded }')
print('>>>Esse programa procura arquivos para deletar de acordo com o nome')
print('>Qual directório deseja escanear?')
directory = input()
print('>Qual o nome do arquivo?')
filename = input()
threading.Thread(target=print_run).start()
search_for_files(directory, filename)
print(f'>Total de arquivos escaneados: { number_files }')
if len(files) > 0:
confirm_exluding()
else:
print(f'>>>Nenhum arquivo encontrado!')