Skip to content

Instantly share code, notes, and snippets.

@f5-rahm
Created February 26, 2025 16:58
Show Gist options
  • Save f5-rahm/9063a133b72184f56defaacec7bf4724 to your computer and use it in GitHub Desktop.
Save f5-rahm/9063a133b72184f56defaacec7bf4724 to your computer and use it in GitHub Desktop.
import os
def find_matching_file(smartsheet_filename, input_filename, directory):
# Normalize input filenames by converting to lowercase and removing .mp4 if present
def normalize_filename(filename):
filename = filename.lower().rstrip('.mp4') # Remove trailing ".mp4" (case-insensitive)
return filename
normalized_smart_filename = normalize_filename(smartsheet_filename)
normalized_input_filename = normalize_filename(input_filename)
# Iterate through the files in the directory
for file in os.listdir(directory):
normalized_file = normalize_filename(file) # Normalize the filesystem filename
# If any of the normalized names match, return the actual filename
if (normalized_file == normalized_smart_filename or
normalized_file == normalized_input_filename):
return os.path.join(directory, file) # Return the actual file path
return None # No match found
# Example usage:
smartsheet_filename = "1Subtest.MP4" # Example from Smartsheet
input_filename = "1subtest" # Example user input
directory = "/path/to/videos" # Path where videos are stored
matched_file = find_matching_file(smartsheet_filename, input_filename, directory)
if matched_file:
print(f"Matched file: {matched_file}")
else:
print("No matching file found.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment