os模块关于路径

来源:互联网 发布:2015全球社交网络排名 编辑:程序博客网 时间:2024/06/06 17:31

os模块关于路径的几个主要方法

os.path 模块路径访问函数os.path.basename() 去掉目录路径,返回文件名os.path.dirname() 去掉文件名,返回目录路径os.path.split()  将路径分为(dirname,basename)元组os.path.join()  将目录路径和文件问合为一个路径   os.path.getatime() 获取最近访问时间os.path.getctime() 获取文件创建时间os.path.getmtime() 获取文件修改时间os.path.getsize() 获取文件大小 os.path.exists() 路径是否存在os.path.isabs() 路径是否为绝对路径os.path.isdir() 路径是否为一个目录os.path.sifile() 路径是否是一个文件os.path.islink() 路径是否是一个链接os.path.samefile() 两个路径是否指向同一个文件os.path.ismount() 路径是否是挂载点 os.getcwd() 获取当前目录os.listdir() 列出指定目录的文件或目录os.chdir()  切换当前目录os.mkdir() /os.makedirs()  创建目录/创建多层目录os.rmdir() /os.removedirs() 删除目录/删除多层目录 os.rename('shou.txt','shou3.txt') 重命名os.walk() 生成一个目录树下所有文件名os.mknod() 生产一个文件os.symlink() 生成链接os.remove()/os.unline 删除一个文件/删除一个链接 shutil.move() 移动文件shutil.copy(src,dst) 复制文件shutil.copymode(src, dst) 只复制权限,不复制路径shutil.copytree(olddir, newdir, True) 复制目录shutil.retree(src) 删除目录