當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pathlib.Path.exists用法及代碼示例

用法:

Path.exists()

路徑是否指向現有文件或目錄:

>>> Path('.').exists()
True
>>> Path('setup.py').exists()
True
>>> Path('/etc').exists()
True
>>> Path('nonexistentfile').exists()
False

注意

如果路徑指向符號鏈接,exists() 返回符號鏈接 points to 是否為現有文件或目錄。

相關用法


注:本文由純淨天空篩選整理自python.org大神的英文原創作品 pathlib.Path.exists。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。