python模块详解 | os

osos.remove(path) 删除文件

  • os.remove(path) - 删除文件
  • os.removedirs(path) - 删除空文件夹
  • os.mkdir(dirname) - 新建文件夹
  • os.makedirs(path) - 递归新建文件夹
  • os.rmdir(path) - 删除空文件夹
  • os.rename(a,b) - 重命名
  • os.listdir(path) - 返回路径下所有的文件及文件夹
  • os.system("ls") - 运行shell命令

os.path

  • os.path.getatime(path) - 最近访问时间(时间戳)
  • os.path.getctime(path) - 文件创建时间(时间戳)
  • os.path.getmtime(path) - 最近修改时间(时间戳)
  • os.path.getsize(path) - 文件大小(字节为单位)
  • os.path.abspath(path) - 绝对路径
  • os.path.normpath(path) - path路径
  • os.path.dirname(path) - path的目录
  • os.path.basename(path) - path最后的文件名
  • os.path.exists(path) - 存在则返回True
  • os.path.isabs(path) - path是绝对路径则返回True
  • os.path.isfile(path) - path对象为文件,则返回True
  • os.path.isdir(path) - path对象为文件夹,则返回True
  • os.path.join(path,file) - 合并路径与文件名
  • os.path.split(path) - 将文件名和路径分割开
  • os.path.splitext(path) - 将文件名与拓展名分割开

更多内容猛击这里


274 字