Python でディレクトリの存在を確認する

published:

Python の os モジュールを使って、ディレクトリの存在(有無)を確認する。

ディレクトリの存在を確認する例

os.path.isdir() 関数を使用。
if 文で、ファイルが存在する場合、存在しない場合の処理を行なっている。

import os.path
if os.path.isdir('./example/'):
    print('有り')
else:
    print('無し')

Previous Article

Next Article