Skip to content

Commit

Permalink
Updated matches variable in list_files.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryjcannon committed Jan 5, 2024
1 parent 7ec4bb7 commit cd3b3bb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/alpineer/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ def list_files(dir_name, substrs=None, exact_match=False, ignore_hidden=True):
if any([substr == os.path.splitext(file)[0] for substr in substrs])
]
else:
matches = []
matches_list = []
for substr in substrs:
# Create a regular expression pattern from substrs with word boundaries
pattern = "|".join(re.escape(part) + r"\b" for part in substr.split("_"))
# Use re.search to check if any of the substrings exactly match in the file names
substr_matches = [file for file in files if re.search(pattern, file)]
# append matches for this substr to larger matches list.
matches.append(substr_matches)
matches_list.append(substr_matches)
# Flatten the list of match lists
flattened_matches = [file for match in matches for file in match]
matches = [file for match in matches_list for file in match]

return flattened_matches
return matches


def remove_file_extensions(files):
Expand Down

0 comments on commit cd3b3bb

Please sign in to comment.