-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleanup_orphan_dirs.py
43 lines (32 loc) · 987 Bytes
/
cleanup_orphan_dirs.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
import argparse
import filetype
import os
import shutil
def main():
args = term_args()
if args.path is None:
print("Please provide directory!")
exit(1)
directory = args.path
paths = []
# Only looking leaf directorys containing one image file
for root, dirs, files in os.walk(directory):
if len(files) == 1 and filetype.is_image(os.path.join(root,files[0])) and not dirs:
paths.append(root)
print(root)
if paths:
print()
print("Delete the following directories?")
print("[Y]es, [N]o")
choice = input("> ").lower().strip()
if choice == "y":
for path in paths:
shutil.rmtree(path)
else:
print("No directories found!")
def term_args():
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--path", type=str, help="Path to be searched.")
return parser.parse_args()
if __name__ == '__main__':
main()