import os

os
os.getcwd() 返回当前工作目录
path=os.chdir("E://") 改变工作目录
os.listdir(path)/os.listdir('.') 列出指定目录中的文件名,('.')当前目录('..')上级目录
os.mkdir("D://hell") 创建目录,如果已存在,则抛出异常
os.makedirs("D://hell//nacy//each") 递归创建多层目录
remove(path) 删除目录
rmdir(path) 删除单层目录,如果目录非空则抛出异常
removedirs() 递归删除目录,从子目录到父目录尝试删除,如果非空,则抛出异常
rename(old,new)

将文件old命名为new

os.system(command) 运行系统的shell命令 #似乎是错的
os.walk(path) 遍历path路径下所有的子目录,返回一个三元组(路径,包含目录,包含文件)
   
os.curdir 指代当前目录 '.'
os.pardir 指代上级目录 '..'
os.sep 输出操作系统路径分隔符
os.linesep

当前平台使用的终止符

os.name 指代当前操作系统

对于路径的修改

os.path.basename(path) 单独返回文件名
os.path.dirname(path) 单独返回目录路径
os.path.join(path1,path2,path3) 组合为一个路径
os.path.split(path) 分割文件名与路径
os.path.splitext(path) 分离文件与扩展名
os.path.getsize(path) 获得文件大小,单位字节*1024*1024=MB
os.path.getatime(file) 返回最近访问时间,(浮点型秒数,可用time模块的gmtime()或localtime()函数转换)
os.path.getctime(file) 返回文件创建时间
os.path.getmtime() 返回文件最新修改时间
os.path.exists(path) 判断路径是否存在
os.path.isabs(path) 判断是否为绝对路径
os.path.isdir(path) 判断是否为目录
os.path.isfile(path) 判断是否为文件
os.path.islink(path) 判断是否为符号链接
os.path.ismount(path) 判断是否为挂载点
os.path.samefile(path1,path2) 判断是否为路径是否指向同一个文件

猜你喜欢

转载自blog.csdn.net/qq_41375702/article/details/88198852