「Python」isdir()でフォルダの存在を確認する方法

書式
os.path.isdir(パス名):
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
import os
pt = "C:\\study"
if os.path.isdir(pt):
print("folder exist")
else:
print("folder not exist")
# coding: utf-8 import os pt = "C:\\study" if os.path.isdir(pt): print("folder exist") else: print("folder not exist")
# coding: utf-8
import os

pt = "C:\\study"

if os.path.isdir(pt):
      print("folder exist")
else:
      print("folder not exist")

 

Python

Posted by arkgame