-
Notifications
You must be signed in to change notification settings - Fork 0
/
34-delete-a-file.py
40 lines (32 loc) · 927 Bytes
/
34-delete-a-file.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
import os
# file
# path = "34-delete-a-file.txt"
# try:
# os.remove(path)
# except FileNotFoundError :
# print("file doesn't exist")
# folder empty
# path = "empty_folder" #folder to delete's path
# try:
# os.rmdir(path)
# except FileNotFoundError:
# print("that folder or file was not found")
# except PermissionError:
# print("you do not have permission to delete that")
# except OSError:
# print("you cant delete that using that function")
# else :
# print(path+" was deleted")
# not empty folder
import shutil
path = 'empty_folder' # folder to delete path
try:
shutil.rmtree(path) #delete a directory containing files
except FileNotFoundError:
print("that folder or file was not found")
except PermissionError:
print("you do not have permission to delete that")
except OSError:
print("you cant delete that using that function")
else :
print(path+" was deleted")