Python中判断所给路径是文件还是目录
2018-05-16 本文已影响8人
氕氘氚0921
在python中有时不知道所给的路径是目录还是文件,可以用下面方法判断所给的路径是目录还文件,或者其他类型。
def get_path_type(path):
if os.path.isdir(path):
return 'dir'
if os.path.isfile(path):
return 'file'
return 'other'