utils.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:differ 作者: MadRussian 项目源码 文件源码
def get_file_type(path):
  """Retrieve the file type of the path

  :param path: The path to get the file type for
  :return: The file type as a string or None on error
  """
  f_types = {
    'socket':           stat.S_IFSOCK,
    'regular':          stat.S_IFREG,
    'block':            stat.S_IFBLK,
    'directory':        stat.S_IFDIR,
    'character_device': stat.S_IFCHR,
    'fifo':             stat.S_IFIFO,
  }
  if not path or not os.path.exists(path):
    return None

  obj = os.stat(path).st_mode
  for key,val in f_types.items():
    if obj & val == val:
      return key
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号