To get the file extension in python you can use the following snippet.

Sample Python

import os.path  
filePath = "C:\Users\Codesnippets\Desktop\testfolder\test.bat"
print os.path.splitext(filePath)[1]

2 thought on “How to get the file extension in Python”

Leave a Reply