-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
24 lines (20 loc) · 731 Bytes
/
utils.py
File metadata and controls
24 lines (20 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
def reorder_files(path: str) -> None:
"""
Remove any subdirectories in the given path and reorder the files in the
directory adding the name of the directory to the filename
"""
for dir in os.listdir(path):
dir_path = os.path.join(path, dir)
if os.path.isdir(dir_path):
for file in os.listdir(dir_path):
file_path = os.path.join(dir_path, file)
os.rename(file_path, os.path.join(path, dir + "_" + file))
os.rmdir(dir_path)
def clean_dir(path: str) -> None:
"""
Remove all files in the given directory
"""
for file in os.listdir(path):
file_path = os.path.join(path, file)
os.remove(file_path)