るりまサーチ (Ruby 2.3.0)

最速Rubyリファレンスマニュアル検索!
9件ヒット [1-9件を表示] (0.038秒)
トップページ > バージョン:2.3.0[x] > クエリ:new[x] > クラス:File[x]

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

ライブラリ

キーワード

検索結果

File.new(path, mode = "r", perm = 0666) -> File (54343.0)

path で指定されるファイルをオープンし、File オブジェクトを生成して 返します。

...File オブジェクトを生成して
返します。

path が整数の場合はファイルディスクリプタとして扱い、それに対応する
File
オブジェクトを生成して返します。IO.open と同じです。
ブロックを指定して呼び出した場合は、File...
...mlist[例: File.new による読み込みモードでのファイルオープン][ruby]{
f = File.new("testfile", "r")
f.class # => File
f.close
//}

//emlist[例: File.open による読み込みモードでのファイルオープン][ruby]{
f = File.open("testfile", "r")
f.class # => File
f.close...
...//}

//emlist[例: File.open による書き込みモードでのファイルオープン][ruby]{
File
.open("testfile", "w", 0755) { |f| f.print "test" }
File
.read("testfile") # => "test"
//}...

File.open(path, mode = "r", perm = 0666) -> File (9043.0)

path で指定されるファイルをオープンし、File オブジェクトを生成して 返します。

...File オブジェクトを生成して
返します。

path が整数の場合はファイルディスクリプタとして扱い、それに対応する
File
オブジェクトを生成して返します。IO.open と同じです。
ブロックを指定して呼び出した場合は、File...
...mlist[例: File.new による読み込みモードでのファイルオープン][ruby]{
f = File.new("testfile", "r")
f.class # => File
f.close
//}

//emlist[例: File.open による読み込みモードでのファイルオープン][ruby]{
f = File.open("testfile", "r")
f.class # => File
f.close...
...//}

//emlist[例: File.open による書き込みモードでのファイルオープン][ruby]{
File
.open("testfile", "w", 0755) { |f| f.print "test" }
File
.read("testfile") # => "test"
//}...

File.open(path, mode = "r", perm = 0666) {|file| ... } -> object (9043.0)

path で指定されるファイルをオープンし、File オブジェクトを生成して 返します。

...File オブジェクトを生成して
返します。

path が整数の場合はファイルディスクリプタとして扱い、それに対応する
File
オブジェクトを生成して返します。IO.open と同じです。
ブロックを指定して呼び出した場合は、File...
...mlist[例: File.new による読み込みモードでのファイルオープン][ruby]{
f = File.new("testfile", "r")
f.class # => File
f.close
//}

//emlist[例: File.open による読み込みモードでのファイルオープン][ruby]{
f = File.open("testfile", "r")
f.class # => File
f.close...
...//}

//emlist[例: File.open による書き込みモードでのファイルオープン][ruby]{
File
.open("testfile", "w", 0755) { |f| f.print "test" }
File
.read("testfile") # => "test"
//}...

File.link(old, new) -> 0 (373.0)

old を指す new という名前のハードリンクを 生成します。old はすでに存在している必要があります。 ハードリンクに成功した場合は 0 を返します。

...を指定します。

@param new ファイル名を表す文字列を指定します。

@raise Errno::EXXX 失敗した場合に発生します。

//emlist[例][ruby]{
IO.write("testfile", "test")
File
.link("testfile", "testlink") # => 0
IO.read("testlink") # => "test"
//}...

File.symlink(old, new) -> 0 (373.0)

old への new という名前のシンボリックリンクを生成します。

...発生します。

@param old ファイル名を表す文字列を指定します。

@param new シンボリックリンクを表す文字列を指定します。

@raise Errno::EXXX 失敗した場合に発生します。

//emlist[例][ruby]{
File
.symlink("testfile", "testlink") # => 0
//}...

絞り込み条件を変える

File.utime(atime, mtime, *filename) -> Integer (40.0)

ファイルの最終アクセス時刻と更新時刻を変更します。

...秒数を数値で指定します。

@param mtime 更新時刻を Time か、起算時からの経過秒数を数値で指定します。

@param filename ファイル名を表す文字列を指定します。複数指定できます。

@return 変更したファイルの数を返します。

@ra...
...5, 6)
File
.utime(atime, mtime, "testfile") # => 1
File
.atime("testfile") # => 2018-01-02 03:04:05 +0900
File
.mtime("testfile") # => 2018-02-03 04:05:06 +0900
//}

//emlist[例: 経過秒数で指定][ruby]{
File
.utime(1, 2, "testfile") # => 1
File
.atime("testfile")...
...# => 1970-01-01 09:00:01 +0900
File
.mtime("testfile") # => 1970-01-01 09:00:02 +0900
//}...

File#birthtime -> Time (22.0)

作成された時刻を Time オブジェクトとして返します。

...::EXXX ファイルの時刻の取得に失敗した場合に発生します。

@raise NotImplementedError Windows のような birthtime のない環境で発生します。

File
.new("testfile").birthtime #=> Wed Apr 09 08:53:14 CDT 2003

@see File#lstat, File#atime, File#ctime, File#mtime...

File#chmod(mode) -> 0 (22.0)

ファイルのモードを指定された mode に変更します。

...EXXX が発生し
ます。

@param mode chmod(2) と同様に整数で指定します。

@raise IOError 自身が close されている場合に発生します。

@raise Errno::EXXX 失敗した場合に発生します。

//emlist[例][ruby]{
f = File.new("out", "w");
f.chmod(0644) #=> 0
//}...

File.path(filename) -> String (22.0)

指定されたファイル名を文字列で返します。filename が文字列でない場合は、to_path メソッドを呼びます。

...指定されたファイル名を文字列で返します。filename が文字列でない場合は、to_path メソッドを呼びます。

@param filename ファイル名を表す文字列か to_path メソッドが定義されたオブジェクトを指定します。

//emlist[例][ruby]{
requ...
...ire 'pathname'

class MyPath
def initialize(path)
@path = path
end
def to_path
File
.absolute_path(@path)
end
end

File
.path("/dev/null") # => "/dev/null"
File
.path(Pathname("/tmp")) # => "/tmp"
File
.path(MyPath.new(".")) # => "/Users/user/projects/txt"
//}...