Home  >  Article  >  Backend Development  >  How to get file extension

How to get file extension

anonymity
anonymityOriginal
2019-05-25 09:21:135339browse

How to get the file extension?

First analyze the problem:

How to get file extension

#The file extension form is separated by "." after the file path, so we can use Python's string interception Select to get the file extension.

 def get_file_extension(filename):   
 arr = os.path.splitext(filename)
    return arr[len(arr) - 1]
    #return arr[len(arr) - 1].replace(".","") 可以将结果中的.去掉
 
 
print(get_file_extension("abc.jpg"))
#返回 .jpg
 
print(get_file_extension("2014.01.25.gif"))
#返回 .gif

The above is the detailed content of How to get file extension. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn