Python/サンプル/ファイルの有無・ディレクトリの有無を確認する
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* Pythonでファイルの有無・ディレクトリの有無を確認する [#...
Pythonでファイル、ディレクトリの有無をチェックするサンプ...
#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)
* 関連記事 [#s6855b73]
-[[Pythonスクリプトを実行しているパス(ディレクトリ)を取得...
-[[Pythonスクリプトが存在するパス(ディレクトリ)を取得する...
-[[Pythonのスクリプト名を取得する>Python/サンプル/スクリ...
-[[Pythonでテキストファイルを1行ずつ読み込む>Python/サン...
-[[Pythonでディレクトリを作成・削除する>Python/サンプル/...
-[[Pythonでファイルの有無・ディレクトリの有無を確認する>P...
-[[Pythonでディレクトリかファイルかどうかを調べる方法>Pyt...
* 動作環境 [#ta2f1899]
$ python --version
Python 2.7.3
$ lsb_release -d
Description: Ubuntu 12.04.4 LTS
* ファイル・ディレクトリの有無を確認する [#s1ba6d11]
ファイルの有無を確認する構文は以下の通りです。
import os.path
os.path.exists("ファイルorディレクトリ")
os.path.exists()で有無判定されTrueまたはFalseが返却されま...
以下にサンプルコードおよび実行出力結果を記します。
-サンプルコード
#ref(exists.py)
import os.path
print os.path.exists("/etc") # directory
print os.path.exists("/etc/passwd") # file
print os.path.exists("/ETC") # directory
print os.path.exists("/etc/hogehoge") # file
-実行結果
$ python exists.py
True
True
False
False
ファイルまたはディレクトリが存在すればTrueが返却し存在し...
以上、ファイル・ディレクトリの有無を確認するサンプルコー...
#htmlinsertpcsp(ll-btm.html,ll-sp.html)
終了行:
#navi(../)
* Pythonでファイルの有無・ディレクトリの有無を確認する [#...
Pythonでファイル、ディレクトリの有無をチェックするサンプ...
#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)
* 関連記事 [#s6855b73]
-[[Pythonスクリプトを実行しているパス(ディレクトリ)を取得...
-[[Pythonスクリプトが存在するパス(ディレクトリ)を取得する...
-[[Pythonのスクリプト名を取得する>Python/サンプル/スクリ...
-[[Pythonでテキストファイルを1行ずつ読み込む>Python/サン...
-[[Pythonでディレクトリを作成・削除する>Python/サンプル/...
-[[Pythonでファイルの有無・ディレクトリの有無を確認する>P...
-[[Pythonでディレクトリかファイルかどうかを調べる方法>Pyt...
* 動作環境 [#ta2f1899]
$ python --version
Python 2.7.3
$ lsb_release -d
Description: Ubuntu 12.04.4 LTS
* ファイル・ディレクトリの有無を確認する [#s1ba6d11]
ファイルの有無を確認する構文は以下の通りです。
import os.path
os.path.exists("ファイルorディレクトリ")
os.path.exists()で有無判定されTrueまたはFalseが返却されま...
以下にサンプルコードおよび実行出力結果を記します。
-サンプルコード
#ref(exists.py)
import os.path
print os.path.exists("/etc") # directory
print os.path.exists("/etc/passwd") # file
print os.path.exists("/ETC") # directory
print os.path.exists("/etc/hogehoge") # file
-実行結果
$ python exists.py
True
True
False
False
ファイルまたはディレクトリが存在すればTrueが返却し存在し...
以上、ファイル・ディレクトリの有無を確認するサンプルコー...
#htmlinsertpcsp(ll-btm.html,ll-sp.html)
ページ名: