您的位置:首页 > 编程语言 > Python开发

怎样使用 Python 来判断一个路径是否存在判断一个路径是文件还是目录

2015-12-13 17:10 1021 查看
参考链接:http://www.pfinn.net/python-check-if-file-exists.html

怎样使用 Python 来判断一个路径是否存在判断一个路径是文件还是目录

判断一个路径是否存在

可以判断一个文件或目录(文件夹)是否存在

import os.path
os.path.exists(path);


判断一个文件是否存在

import os.path
os.path.isfile(path);


判断一个目录(文件夹)是否存在

import os.path
os.path.isdir(path);


判断一个路径是文件还是目录(文件夹)

方法一

import os.path
os.path.isdir(path);# 返回 True 表示是目录(文件夹)



方法二

import os.path
os.path.isfile(path);# 返回 True 表示是文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: