|
Simple Sand Samples |
Python > ファイルやディレクトリの存在を調べる
exists.py
import os.path
if os.path.exists("hoge.txt"):
print "Found."
else:
print "Not Found."
$ python exists.py
Not Found.
$ touch hoge.txt
$ python exists.py
Found.
$
Not Found.
$ touch hoge.txt
$ python exists.py
Found.
$
* 確認環境 Debian Linux(Wheezy)