python os.path.exists判断文件或文件夹是否存在
生活随笔
收集整理的這篇文章主要介紹了
python os.path.exists判断文件或文件夹是否存在
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import os#判斷文件夾是否存在
dir = os.path.exists('C:\\Users\\Desktop')
print('dir:', dir)#判斷文件是否存在
file = os.path.exists('C:\\Users\\Desktop\\雍正王朝.txt')
print('file:', file)
運行結果
顯示該文件及文件夾都存在
總結
以上是生活随笔為你收集整理的python os.path.exists判断文件或文件夹是否存在的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab 字符串处理
- 下一篇: python os.listdir列举