-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.py
More file actions
35 lines (27 loc) · 1.17 KB
/
cleanup.py
File metadata and controls
35 lines (27 loc) · 1.17 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
import os
import glob
def clean_up_specific_files(directory):
"""
Removes specific files and files matching a pattern within the specified directory.
:param directory: The path to the directory where files will be removed.
"""
# Files and patterns to delete
files_and_patterns = [
"abundances.png",
"detonation_lengths.png",
"reaction_flow_*.png" # This will match all files starting with 'reaction_flow_' and ending with '.png'
]
# Iterate over each file/pattern to delete them
for item in files_and_patterns:
full_path_pattern = os.path.join(directory, item)
# For patterns, glob.glob will find matches. For specific files, it will return the file if it exists.
files_to_delete = glob.glob(full_path_pattern)
for file_path in files_to_delete:
try:
os.remove(file_path)
print(f"Deleted {file_path}")
except Exception as e:
print(f"Error deleting {file_path}: {e}")
# Use the current working directory as the directory to clean
current_directory = os.getcwd()
clean_up_specific_files(current_directory)