def parse_and_format_filenames(directory):
# Define possible sample names
sample_names = [
"SSB1", "SSB2", "SSBD1", "SSBD2", "SSW1", "SSW2", "SSW3", "SSW4",
"SSWO31", "SSWO32", "SSWO33", "SSWO34"
]
# Set to store formatted filenames
formatted_filenames = set()
# List all files in the directory
for filename in os.listdir(directory):
if filename.endswith('.csv'):
# Extract the basename without extension
base_filename = os.path.splitext(filename)[0]
# Determine the sample name and format the filename
for sample_name in sample_names:
if base_filename.startswith(sample_name):
# Extract zone and energy
zone_energy_part = base_filename[len(sample_name):] # Remainder after sample name
zone = 'z' + zone_energy_part[0] # First digit after sample name is zone
energy = zone_energy_part[1:] # Remainder is energy with 'kV'
reformatted_sample_name = sample_name
formatted_filename = f"{reformatted_sample_name}-{zone}-{energy}"
formatted_filenames.add(formatted_filename)
break # Stop looking through sample names once a match is found
return formatted_filenames
List of available files
Sample Name
Zone