以下の内容はhttps://tbpgr.hatenablog.com/entry/20140111/1389446113より取得しました。


Ruby | File | exists?

概要

File.exists?

詳細

ファイルまたはディレクトリが存在するか判定する。

サンプル

コード

カレントディレクトリがWindowsのC:\tmpだったとします。

# encoding: utf-8

def create_file(filename, contents)
  File.open(filename, 'w:utf-8') do |f|
    f.print contents
  end
end

filenames = ['sample1.txt', 'sample2.txt']
p File.exists? 'tmp'
p File.exists? 'sample1.txt'
Dir.mkdir('tmp') unless File.exists?('tmp')
filenames.each {|f|create_file f, "test"}
p File.exists? 'tmp'
p File.exists? 'sample1.txt'
出力
false
false
true
true



以上の内容はhttps://tbpgr.hatenablog.com/entry/20140111/1389446113より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14