os.getcwd() -----当前目录 =Linux中的pwd
os.chdir("c:\Users") ---- or ---- os.chdir(r"c:Users")----切换目录 ; 等于shell中cd
os.curdir----返回当前目录
os.pardir-----回到当前目录的父目录
os.makedirs(r"c:acd")------可以递归的创建目录
os.removedirs(r"c:acd")------递归删除,若目录为空则删除,到上级清理空文件夹
os.mkdir()------非递归创建
os.rmdir()-------非递归删除空目录,不为空则报错;等于shell中rmdir
os.listdir(r'D:')------列出指定目录下的所有文件和子目录,以列表的方式打印
remove()---删除一个文件
rename(“oldname”,“newname”)-----重命名文件
stat('path/filename)------获取文件/目录信息
os.sep ---输出操作系统特定的路径分隔符,win下为“\”Linux下为“/”
os.linesep输出当前平台使用的行终止符,win下为“ ”,linux下为“ ”
os.pathsep输出用分割文件路径的字符串
os.environ-----环境变量
os.name------输出当前什么系统平台 win=nt
os.system("bash command)----运行shell命令
os.path.abspath(path)-----获取当前目录 的绝对路径
os.path.split(path)-----将path分割成目录和文件名二元组返回,不考虑文件是否存在
os.path.dirname(r‘c:aca.txt’’)----取文件的目录名,不考虑文件是否存在
os.path.basename(r‘c:aca.txt’’)----取文件名,不考虑文件是否存在
os.path.exists()---判断你输入的路径是否存在
os.path.isabs(r'c:a')---判断是否是绝对路径(r'c:a')或者(r'a')
os.path.isfile(r'c:client.txt')----判断是否是文件
os.path.isdir(path)----判断是否是目录
os.path.join(path[,path2[,...]])---将多个路径组合返回,第一个绝对路径之前的参数将被忽略
os.path.join(r'c:',r'a.txt',)
os.path.getatime(path)---返回最后存储时间
os.path.getmtime(path)---返回最后修改时间