Python3 内置模块 - os.path

方法 说明
os.path.abspath(name) 获得绝对路径
os.path.basename(filename) 返回文件路径的文件名部分
os.path.commonprefix(list) 返回list(多个路径)中,所有path共有的最长的路径
os.path.dirname(filename) 返回文件路径的目录部分
os.path.exists() 判断文件或目录是否存在
os.path.expanduser(path) 把path中包含的””和”user”转换成用户目录
os.path.expandvars(path) 根据环境变量的值替换path中包含的” n a m e name”和” {name}”
os.path.getatime() 返回最近访问时间 浮点型
os.path.getctime() 返回文件创建时间 浮点型
os.path.getmtime() 返回上一次修改时间 浮点型
os.path.getsize() 返回文件大小 字节单位
os.path.isabs() 如果path是绝对路径,返回True
os.path.isdir() 判断name是不是一个目录,name不是目录就返回false
os.path.isfile() 判断name是不是一个文件,不存在返回false
os.path.islink() 判断文件是否连接文件,返回boolean
os.path.ismount() 指定路径是否存在且为一个挂载点,返回boolean
os.path.join(dirname,basename) 将文件路径和文件名凑成完整文件路径
os.path.lexists 路径存在则返回True,路径损坏也返回True
os.path.normcase(path) 转换path的大小写和斜杠
os.path.normpath(path) 规范path字符串形式
os.path.realpath(path) 返回path的真实路径
os.path.relpath(path[, start]) 从start开始计算相对路径
os.path.samefile() 是否相同路径的文件,返回boolean
os.path.sameopenfile(fp1, fp2) 判断fp1和fp2是否指向同一文件
os.path.samestat(stat1, stat2) 判断stat tuple stat1和stat2是否指向同一个文件
os.path.split(filename) 将文件路径和文件名分割(会将最后一个目录作为文件名而分离)
os.path.splitdrive(path) 一般用在windows下,返回驱动器名和路径组成的元组
os.path.splitext(filename) 将文件路径和文件扩展名分割成一个元组
os.path.splitunc(path) 把路径分割为挂载点和文件名
os.path.supports_unicode_filenames() 设置是否支持unicode路径名
os.path.walk(path, visit, arg) 遍历path,给每个path执行一个函数详细见手册
发布了27 篇原创文章 · 获赞 3 · 访问量 1128

猜你喜欢

转载自blog.csdn.net/qq_39609993/article/details/104757374