
Pythonで
・ファイルの存在有無を確認
できます!
コード
ここでは例として
・デスクトップ配下のファイル「aiueo.txt」の存在有無を確認
します。
※デスクトップ上に下記コードを記載した「sample.py」を作成します。
import os
# 対象のファイルパス
file = r"C:\Users\user\Desktop\aiueo.txt"
if os.path.exists(file):
print("ファイルは存在します。")
else:
print("ファイルは存在しません。")
実行結果
ファイルの存在有無を確認できました。

参考①
標準ライブラリ「os.path」モジュールの「exists」でも、ファイルの存在有無を確認できます。
import os
# 対象のファイルパス
filePath = r"C:\Users\user\Desktop\aiueo.txt"
if (os.path.exists(filePath)):
print("ファイルは存在します。")
else:
print("ファイルは存在しません。")
参考②
上記のコードで使用した以下の詳細は、公式サイトをご確認ください。
●標準ライブラリ「os.path」モジュールの「isfile」
●標準ライブラリ「os.path」モジュールの「exists」