I made this program to automate/simplify the erasing of a lot of files, I have some ideas to improve it but that's not why I'm putting it here, it's because it's a very dangerous program(it deletes stuff permanently) and since I'm a beginner(ish) I want some advice from better programmers to improve it.
import os
import send2trash
import shutil
file = input("Type the file path")
while os.path.exists(file) is False: # validation
file = input("Path not found, try again:")
for i, j, k in os.walk(file): # files check
print("The folder is in this path:", i)
print("The subfolders are named:", j)
print("The files are named:", k)
while True:
try:
command = int(input("1 - Delete permanently the file\n2 - Send the file to the bin"))
except ValueError:
print("Just the numbers 1 or 2 are accepted, follow the instructions")
continue
if command not in range(1, 3):
print("Just the numbers 1 or 2 are accepted, follow the instructions")
continue
else:
break
if command == 1:
try:
os.rmdir(file) # deletes if there is no inside folder
except OSError:
shutil.rmtree(file) # deletes if there is inside folders
else:
send2trash.send2trash(file) # send to the bin
0
- currently my only option is to kill the program. \$\endgroup\$Ctrl-C
will raise aKeyboardInterrupt
. \$\endgroup\$