Section Menu:  

判断文件或路径是否存在函数:exists()

  • 发布时间: 2019-08-28 00:00
  •    阅读: 2447   

描述

exists() 判断文件或路径是否存在。
exists() 接收两个参数,第一个为文件或路径,第二个为检测类型,文件或目录。


 
语法

以下是 exists() 的语法:

exists(path, type='dir')

参数

    ● path [str]:文件或路径。
    ● type [str]:dir:检测目录是否存在,file:检测文件是否存在。


返回值

返回布尔类型。


实例

以下展示了使用 exists() 的实例:

from kyger.utility import exists
print(exists('static/404'))  # 判断目录是否存在
print(exists('static/kgcms.json', type='file'))  # 判断文件是否存在

以上实例运行后输出的结果为:

True
False

适应版本

v1.0.1