python的使用OS模块
判断文件是是否存在
os.path.isfile(path)
判断目录是否存在
os.path.isdir(path)
判断文件是否存在
#使用path模块
os.path.exists(path)
#使用access()方法
os.access(path,os.F_OK)
使用pathlib模块
importpathlib
path=pathlib.Path('path/to/file')
#判断路径是否存在
path.exists()
#判断是否为文件
path.is_file()
#判断是否为目录
path.is_dir()
以上内容为大家介绍了python培训之判断目录是否存在,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注我们