LoginSignup
77

More than 5 years have passed since last update.

pythonでファイルの存在を確認する

Posted at
import os
path = "./sample"

os.path.exists(path)

これでsampleと言う名前のファイル、またはディレクトリの存在を確認できる。

ちなみに、ディレクトリを含まず、ファイルだけを確認したい場合は、

os.path.isfile(path)

ファイルを含まず、ディレクトリだけを確認したい場合は

os.path.isdir(path)

でできる

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
77