Python script in Zapier to detect and remove .mov extension from filename

I’m working on a Python code snippet in Zapier that needs to check if a filename ends with the .mov extension. When it does, I want to remove those last four characters. If the file doesn’t have a .mov ending, I want to return it as it is.

The strange part is that my code only functions properly when I incorporate the .lower() method, and I’m unsure why. Here’s the code I currently have:

file_name = input_data['filename']
if file_name.endswith('.mov'):
    file_name = file_name[:-4]
return {'file_name': file_name.lower()}

I’ve tested several methods, but nothing seems to work unless I convert it to lowercase. I truly want to preserve the original casing of the filename. Has anyone else faced this dilemma? Any suggestions on what could be causing this issue?

The case sensitivity issue happens because different systems handle file extensions inconsistently. Files coming through Zapier from Google Drive, Dropbox, or mobile uploads might have uppercase (.MOV) or mixed case (.Mov) extensions. Your current code with endswith(‘.mov’) only catches lowercase extensions - that’s why it seems unreliable.

Don’t force everything to lowercase in your return statement. Instead, check against multiple case variations in your condition while keeping the original filename. Use if file_name.lower().endswith('.mov'): for the check, then slice the original file_name variable for the return. You’ll maintain the original casing but handle the comparison reliably.

I’ve seen this exact behavior with iPhone uploads through Zapier workflows.

i feel ya, had the same issue! Zapier can be tricky with filename cases, especially from iPhones. Using if file_name.lower().endswith('.mov'): is a solid fix, just remember to use the original file_name when returning it. good luck!

This sounds like a Zapier data handling quirk, not your Python code. Zapier often normalizes file extensions to lowercase when moving data between apps, so your filename might have ‘.MOV’ or ‘.Mov’ instead of ‘.mov’. Since endswith() is case-sensitive, it’s missing these variations. Adding .lower() at the end fixes what you see but doesn’t solve the real issue. Use file_name.lower().endswith('.mov') for your condition check instead - keeps the original casing for output but handles the comparison properly. Or go with file_name.endswith(('.mov', '.MOV', '.Mov')) to catch the common variants. I’ve hit this same casing mess with Zapier before, especially with file uploads from different platforms.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.