-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleaner.py
48 lines (33 loc) · 1.17 KB
/
cleaner.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
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
import os
from preferences import *
def remove_beacons (dirpath: str, beacon_name: str = BEACON_FILENAME):
"""
Recursively remove all beacons from a directory and its subdirectories
:param dirpath: path of the directory to alter
:param beacon_name: filename of the beacon
:return: None
"""
def recur (dirpath: str, beacon_pathlist: list):
# Initialise list of subdirs to parse
subdirs = list()
# Parse current dir
with os.scandir (dirpath) as file_dir:
for file in file_dir:
if file.is_dir():
subdirs.append (file.path)
else:
if file.name == beacon_name:
os.remove (file.path)
# Recursively run for subdirs
for subdirpath in subdirs:
file_dict = recur (subdirpath, beacon_pathlist)
return beacon_pathlist
beacon_pathlist = recur (dirpath, list())
def clean_dir (dirpath: str):
"""
Remove empty children folders within dirpath
:param dirpath: path of the directory to alter
:return: None
"""
pass