本文整理汇总了Python中file.File.getMime方法的典型用法代码示例。如果您正苦于以下问题:Python File.getMime方法的具体用法?Python File.getMime怎么用?Python File.getMime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file.File
的用法示例。
在下文中一共展示了File.getMime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getFilesByMime
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import getMime [as 别名]
def getFilesByMime(self, mime = 'text', recursive = False):
'''Find files by a given MIME type in self._path
@throws InexistentPathError
@param mime string representing the (or part of the) MIME to be matched
@param recursive bool, if it's set to True and self_.path is a directory
the matching will be done recursively,
@return a Collection object consisting of File objects that match or
False if self._path is not a directory
'''
if self._exists:
if os.path.isdir(self._path):
fileCollection = RunCollection()
if recursive:
for root, dirs, files in os.walk(self._path):
for f in files:
path = os.path.join(root, f)
if os.path.isfile(path):
f = File(Path(path, self._cache))
if -1 != f.getMime().find(mime):
fileCollection.add(f)
else:
entries = os.listdir(self._path)
for entry in entries:
path = os.path.join(self._path, entry)
if os.path.isfile(path):
f = File(Path(path, self._cache))
if -1 != f.getMime().find(mime):
fileCollection.add(f)
return fileCollection
else:
return False
else:
raise InexistentPathError(self._path)