os模块:

 1 os.remove() 删除文件 
 2 os.unlink() 删除文件 
 3 os.rename() 重命名文件 
 4 os.listdir() 列出指定目录下所有文件 
 5 os.chdir() 改变当前工作目录
 6 os.getcwd() 获取当前文件路径
 7 os.mkdir() 新建目录
 8 os.rmdir() 删除空目录(删除非空目录, 使用shutil.rmtree())
 9 os.makedirs() 创建多级目录
10 os.removedirs() 删除多级目录
11 os.stat(file) 获取文件属性
12 os.chmod(file) 修改文件权限
13 os.utime(file) 修改文件时间戳
14 os.name(file) 获取操作系统标识
15 os.system() 执行操作系统命令
16 os.execvp() 启动一个新进程
17 os.fork() 获取父进程ID,在子进程返回中返回0
18 os.execvp() 执行外部程序脚本(Uinx)
19 os.spawn() 执行外部程序脚本(Windows)
20 os.access(path, mode) 判断文件权限(详细参考cnblogs)
21 os.wait() 暂时未知
22 os.path模块:
23 os.path.split(filename) 将文件路径和文件名分割(会将最后一个目录作为文件名而分离)
24 os.path.splitext(filename) 将文件路径和文件扩展名分割成一个元组
25 os.path.dirname(filename) 返回文件路径的目录部分
26 os.path.basename(filename) 返回文件路径的文件名部分
27 os.path.join(dirname,basename) 将文件路径和文件名凑成完整文件路径
28 os.path.abspath(name) 获得绝对路径
29 os.path.splitunc(path) 把路径分割为挂载点和文件名
30 os.path.normpath(path) 规范path字符串形式
31 os.path.exists() 判断文件或目录是否存在
32 os.path.isabs() 如果path是绝对路径,返回True
33 os.path.realpath(path) #返回path的真实路径
34 os.path.relpath(path[, start]) #从start开始计算相对路径 
35 os.path.normcase(path) #转换path的大小写和斜杠
36 os.path.isdir() 判断name是不是一个目录,name不是目录就返回false
37 os.path.isfile() 判断name是不是一个文件,不存在返回false
38 os.path.islink() 判断文件是否连接文件,返回boolean
39 os.path.ismount() 指定路径是否存在且为一个挂载点,返回boolean
40 os.path.samefile() 是否相同路径的文件,返回boolean
41 os.path.getatime() 返回最近访问时间 浮点型
42 os.path.getmtime() 返回上一次修改时间 浮点型
43 os.path.getctime() 返回文件创建时间 浮点型
44 os.path.getsize() 返回文件大小 字节单位
45 os.path.commonprefix(list) #返回list(多个路径)中,所有path共有的最长的路径
46 os.path.lexists #路径存在则返回True,路径损坏也返回True
47 os.path.expanduser(path) #把path中包含的”~”和”~user”转换成用户目录
48 os.path.expandvars(path) #根据环境变量的值替换path中包含的”$name”和”${name}”
49 os.path.sameopenfile(fp1, fp2) #判断fp1和fp2是否指向同一文件
50 os.path.samestat(stat1, stat2) #判断stat tuple stat1和stat2是否指向同一个文件
51 os.path.splitdrive(path) #一般用在windows下,返回驱动器名和路径组成的元组
52 os.path.walk(path, visit, arg) #遍历path,给每个path执行一个函数详细见手册
53 os.path.supports_unicode_filenames() 设置是否支持unicode路径名
原文地址:https://www.cnblogs.com/heluobing/p/10963763.html