Python OS模块常用方法

来源:互联网 发布:最好的源码下载网站 编辑:程序博客网 时间:2024/05/21 14:43

os.name

指示你正在使用的平台。比如对于Windows,它是'nt',而对于Linux/Unix用户,它是'posix'。

os.lisdir( )

os.listdir(path)返回指定目录下的所有目录名和文件。

os.system()

用来执行shell命令,如 os.system(pause) 控制台会提示:“请按任意键继续......”

os.path.split()

返回一个路径的目录名字和文件名字

os.path.exists()

检验给出的路径是否真地存在

os.listdir()

os.listdir(path) 列出path下的目录和文件

os.path.isdir()

os.path.isdir(path) 判断path是不是一个目录,path不是目录就返回false 

os.path.isfile()

os.path.isfile(filename) 判断filename是不是一个文件,不存在filename也返回false

os.path.exists()

os.path.exists(name) 判断是否存在文件或目录

os.path.normpath()

os.path.normopath(path) 规范path字符串形式

os.path.split()

分割文件名与目录

os.path.join(path,filename)

连接目录与文件名或目录
原创粉丝点击