「Python」os.path.exists関数の使い方
説明
os.path.exists関数を使用して、フォルダとファイルの存在チェックを行います。
使用例
import os
print(os.path.exists('test.csv'))
print(os.path.exists('user.csv'))
#フォルダの存在チェック
print(os.path.exists('test'))
print(os.path.exists('user'))
import os
print(os.path.exists('test.csv'))
print(os.path.exists('user.csv'))
#フォルダの存在チェック
print(os.path.exists('test'))
print(os.path.exists('user'))
import os print(os.path.exists('test.csv')) print(os.path.exists('user.csv')) #フォルダの存在チェック print(os.path.exists('test')) print(os.path.exists('user'))
実行結果
True
False
True
False