python检测给定的路径是否存在的方法
os.path 模块提供了函数用于检测给定的路径是否存在
1、path 参数所指的文件或文件夹存在,调用os.path.exists(path) 返回 True,否则返回 False
>>>os.path.exists('C:\\Windows') True >>>os.path.exists('C:\\Win') False
2、path 参数存在并且是一个文件,调用 os.path.isfile(path) 返回 True,否则返回 False
>>>os.path.isfile('C:\\Windows\\System32') False >>>os.path.isfile('C:\\Windows\\System32\\C_20280.NLS') True
>>>os.path.isdir('C:\\Windows\\System32\\C_20280.NLS') False >>>os.path.isdir('C:\\Windows\\System32') True
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。