- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to extract file extension using Python?
You can extract the file extension of a filename string using the os.path.splitext method. It splits the pathname path into a pair (root, ext) such that root + ext == path, and ext is empty or begins with a period and contains at most one period.
import os file_name = 'my_file.txt' print(os.path.splitext(file_name))
You will get the output −
- How to change file extension in Python?
- How to get the file extension using PowerShell?
- Perl File Extension
- How to write Python regular expression to match with file extension?
- How to extract all the .txt files from a zip file using Python?
- Get file extension name in Java
- How to get file extension of file as a result of MySQL query?
- Extract csv file specific columns to list in Python
- How can I extract or uncompress gzip file using php?
- Python Program to extract email-id from URL text file
- How to extract numbers from a string using Python?
- How to find a file using Python?
- How to rename a file using Python?
- How to delete a file using Python?
- How to remove a file using Python?