Ruby/サンプル/ディレクトリ・ファイルの有無確認
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* ディレクトリ・ファイルの有無確認方法 [#p91bf36f]
ファイルまたはディレクトリが存在するかしないかを確認する...
有無確認は以下の構文で簡単に調べることができます。
File.exist?(ファイル名orディレクトリ名)
#contents
//#htmlinsert(ll_ads_top.html)
** サンプルコード [#bba027a0]
以下にサンプルコードを記します。
#ref(file_exist.rb)
# check directory
p File.exist?("/tmp")
p File.exist?("/hoge")
# check file
p File.exist?("/etc/hosts")
p File.exist?("/etc/hoge")
** 実行結果 [#f5f8234d]
$ ruby file_exist.rb
true
false
true
false
存在する場合はtrue、しない場合はfalseが返却されます。
//#htmlinsert(ll_ads_btm.html)
終了行:
#navi(../)
* ディレクトリ・ファイルの有無確認方法 [#p91bf36f]
ファイルまたはディレクトリが存在するかしないかを確認する...
有無確認は以下の構文で簡単に調べることができます。
File.exist?(ファイル名orディレクトリ名)
#contents
//#htmlinsert(ll_ads_top.html)
** サンプルコード [#bba027a0]
以下にサンプルコードを記します。
#ref(file_exist.rb)
# check directory
p File.exist?("/tmp")
p File.exist?("/hoge")
# check file
p File.exist?("/etc/hosts")
p File.exist?("/etc/hoge")
** 実行結果 [#f5f8234d]
$ ruby file_exist.rb
true
false
true
false
存在する場合はtrue、しない場合はfalseが返却されます。
//#htmlinsert(ll_ads_btm.html)
ページ名: