Python3 檢測文件真實類型(walker)

測試環境

Windows  10
Python   3.6.7
filetype 1.0.5

安裝 filetype

pip3 install filetype -i https://pypi.doubanio.com/simple/

示例

code

#encoding: utf-8
#author: walker
#date: 2019-11-08
#summary: 檢測(/猜測)真實文件類型

import os
import filetype

def GuessFileType(pathfile):    
    print('GuessFileType %s ...' % pathfile)
    kind = filetype.guess(pathfile)
    print('File name: %s' % os.path.basename(pathfile))
    print('File extension: %s' % kind.extension)
    print('File MIME type: %s' % kind.mime)

if __name__ == '__main__':
    pathfile = r'D:\Python3Project\test\dir.tar.gz'
    GuessFileType(pathfile)

運行

D:\Python3Project\test>python3 t.py
GuessFileType D:\Python3Project\test\dir.tar.gz ...
File name: dir.tar.gz
File extension: zip
File MIME type: application/zip

相關鏈接

walker snapshot
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章