-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles_and_directory_manager.py
More file actions
26 lines (21 loc) · 981 Bytes
/
Copy pathfiles_and_directory_manager.py
File metadata and controls
26 lines (21 loc) · 981 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
25
26
import os
from pathlib import Path
import glob
import re
def remove_part_suffix(filename):
# Use regex to remove '_part#' from the filename
new_filename = re.sub(r'_part\d+', '', filename)
return new_filename
def get_outputfile_paths(parent_dir, output_pattern):
# List to store the full path names of all output files
output_file_paths = []
# Loop through the subdirectories in the parent directory
for subdir in os.listdir(parent_dir):
if subdir.startswith('run'):
# Find all output files in the current run folder that start with output_name
run_folder_path = os.path.join(parent_dir, subdir)
output_files = glob.glob(f"{run_folder_path}/{output_pattern.split('/')[-1]}")
# Add the full path of each output file to the list
for file_path in output_files:
output_file_paths.append(Path(file_path).absolute())
return output_file_paths