python os 文件和目录常用命令
作者:
叶子陪你玩 | 来源:发表于
2019-07-14 11:34 被阅读0次import os
#返回当前工作平台
os.name
#返回当前工作目录
current_directory=os.getcwd()
#改变当前工作目录
os.chdir(path) #return True or False
#返回指定文件目录文件
file_list=os.listdir(path) #return list
#创建目录和删除目录
os.mkdir(path) #return none
os.rmdir(path) #return none
os.makedirs(path) #递归创建
os/removedirs(path)
#os.path模块
os.path.isfile()#判断指定对象是否为文件。是返回True,否则False
os.path.isdir()#判断指定对象是否为目录。是True,否则False。
os.path.exists()#检验指定的对象是否存在。是True,否则False.
os.path.abspath()#获得绝对路径。
os.path.split()#返回路径的目录和文件名
os.path.splitext()#分离文件名与扩展名
os.path.join(path, name)#连接目录和文件名
image.png
本文标题:python os 文件和目录常用命令
本文链接:https://www.haomeiwen.com/subject/uccbkctx.html
网友评论