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


Ruby | File | expand_path

概要

File.expand_path

詳細

第1引数に指定したfilenameを絶対パスに展開する。
第2引数は省略するとカレントディレクトリを基準に。
指定した場合は、指定ディレクトリを基準にします。

サンプル

コード

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

# encoding: utf-8

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

filenames = ['sample1.txt', 'sample2.txt']
filenames.each {|f| create_file f, "test"}
Dir.mkdir('tmp') unless File.exists?('tmp')
p Dir.pwd
filenames.each {|f| p File.expand_path(f)}
Dir.chdir('tmp')
p Dir.pwd
filenames.each {|f| p File.expand_path(f, "../")}
出力
"C:/test"
"C:/test/sample1.txt"
"C:/test/sample2.txt"
"C:/test/tmp"
"C:/test/tmp/sample1.txt"
"C:/test/tmp/sample2.txt"
"C:/test/sample1.txt"
"C:/test/sample2.txt"



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

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