python的使用OS模塊
判斷文件是是否存在
os.path.isfile(path)
判斷目錄是否存在
os.path.isdir(path)
判斷文件是否存在
#使用path模塊
os.path.exists(path)
#使用access()方法
os.access(path,os.F_OK)
使用pathlib模塊
importpathlib
path=pathlib.Path('path/to/file')
#判斷路徑是否存在
path.exists()
#判斷是否為文件
path.is_file()
#判斷是否為目錄
path.is_dir()
以上內容為大家介紹了python培訓之判斷目錄是否存在,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。