-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrmv.py
More file actions
57 lines (46 loc) · 1.96 KB
/
rmv.py
File metadata and controls
57 lines (46 loc) · 1.96 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
import os
Cdir = os.getcwd()
def removeFile(extension, dir):
if dir:
if os.path.exists(dir):
for file in os.listdir(dir):
if os.path.isfile(os.path.join(dir, file)):
if file.endswith(extension):
file_path = os.path.join(dir, file)
try:
os.remove(file_path)
print(f"File '{file_path}' with extension '{extension}' successfully removed.")
except OSError as e:
print(f"Error: {file_path} : {e.strerror}")
else:
print('[-] Directory Path does not exist')
else:
dir = Cdir
if os.path.exists(dir):
for file in os.listdir(dir):
if os.path.isfile(os.path.join(dir, file)):
if file.endswith(extension):
file_path = os.path.join(dir, file)
try:
os.remove(file_path)
print(f"File '{file_path}' with extension '{extension}' successfully removed.")
except OSError as e:
print(f"Error: {file_path} : {e.strerror}")
else:
print('[-] Directory Path does not exist')
def remove_emty_folder(dir):
if dir:
for item in os.listdir(dir):
item_path = os.path.join(dir, item) # Get the full path to the item
if os.path.isdir(item_path):
size_kb = os.path.getsize(item_path) / 1024
if size_kb == 0:
os.rmdir(item_path)
else:
dir = Cdir
for item in os.listdir(dir):
item_path = os.path.join(dir, item) # Get the full path to the item
if os.path.isdir(item_path):
size_kb = os.path.getsize(item_path) / 1024
if size_kb == 0:
os.rmdir(item_path)