-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-files.py
38 lines (24 loc) · 857 Bytes
/
remove-files.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
import os
from lib.inputs import yesNo
from lib.files import traverse
# Absolute path to the directory you want to search
ROOT = r"C:\Users\[Users]\[pythonFiles]"
PREFIX = ''
SUFFIX = '.py'
def removeFiles(path):
assert os.path.isdir(path)
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) if str(f).startswith(PREFIX) and str(f).endswith(SUFFIX)]
print("---FILES---")
for file in files:
print(file)
if yesNo("Delete files (y/n): "):
for file in files:
os.remove(os.path.join(path, file))
print(f"Deleted {len(files)} files")
input("Press ENTER to exit")
def main():
assert os.path.isdir(ROOT)
sourceDir = traverse(ROOT, "Choose source directory (press ENTER to choose CWD): ")
removeFiles(sourceDir)
if __name__ == '__main__':
main()