def get_type(self):
try:
ms = magic.open(magic.MAGIC_NONE)
ms.load()
file_type = ms.file(self.path)
except:
try:
file_type = magic.from_file(self.path)
except:
try:
import subprocess
file_process = subprocess.Popen(['file', '-b', self.path], stdout = subprocess.PIPE)
file_type = file_process.stdout.read().strip()
except:
return ''
finally:
try:
ms.close()
except:
pass
return file_type
评论列表
文章目录