方法 | 说明 |
---|---|
os.getcwd() | 获取当前位置的绝对路径 |
os.listdir(path) | 获取path路径下的所有文件和文件夹(path必须是文件夹路径,如果是个文件会报错) |
os.chdir(path) | Change the current working directory to path |
os. mkdir (path, mode=0o777) | Create a directory named path with numeric(数字的) mode mode. |
os.makedirs(path,mode=0o777) | Create recursive(递归的) directory |
os.rmdir(path) | Remove (delete) the directory path. Only works when the directory is empty, otherwise, OSError is raised. |
os.removedirs(path) | 递归的删除目录(所有目录必须是空的,否则会抛出错误) |
os. rename (src, dst) | Rename the file or directory src to dst. |
os. system (command) | Execute the command (a string) in a subshell. |
os. getenv (key, default=None) | Return the value of the environment variable key if it exists, or default if it doesn’t. key, default and the result are str. |
os.path | |
os.path.isfile(path) | 判断是否是一个文件 |
os.path.isdir(path) | 判断是否是一个路径 |
os.path.islink(path) | 判断是否是一个链接 |
os.path.join(pathA,pathB) | 自动组合路径 |
os.path. exists (path) | Return True if path refers to an existing path or an open file descriptor(描述符). Returns False for broken(断开的) symbolic links. |