Skip to main content

stat

基础使用

import stat

if stat.S_ISREG(st_mode): #判断是否一般文件
print("xxxxx")
elif stat.S_ISLNK(st_mode): #判断是否链接文件
print("xxxxx")
elif stat.S_ISSOCK(st_mode): #判断是否套接字文件
print("xxxxx")
elif stat.S_ISFIFO(st_mode): #判断是否命名管道
print("xxxxx")
elif stat.S_ISBLK(st_mode): #判断是否块设备
print("xxxxx")
elif stat.S_ISCHR(st_mode): #判断是否字符设置
  print("xxxxx")
elif stat.S_ISDIR(st_mode): #判断是否目录
  print("xxxxx")

# 查看文件权限
perm_code = stat.S_IMODE(st_mode)
perm = oct(perm_code)

# 获取文件类型
stat.S_IFMT(st_mode)