Answers for "python how to check extension of path file"

3

python check file extension

# Checking for single extension (.txt) of file
if file.endswith(".txt"):
  # do something
  
# Checking multiple extensions (.txt, .pdf, .mp3, ...)
if file.endswith((".txt", ".pdf", ".mp3")):
  # do something
Posted by: Guest on November-04-2020
2

python get file extension from path

import os.path
extension = os.path.splitext(filename)[1]
Posted by: Guest on May-08-2020

Code answers related to "python how to check extension of path file"

Python Answers by Framework

Browse Popular Code Answers by Language