るりまサーチ (Ruby 2.6.0)

最速Rubyリファレンスマニュアル検索!
7件ヒット [1-7件を表示] (0.225秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:_builtin[x] > バージョン:2.6.0[x] > クエリ:end[x] > クラス:File[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

キーワード

検索結果

File.path(filename) -> String (24064.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"
//}...

File#lstat -> File::Stat (24028.0)

ファイルの状態を含む File::Stat オブジェクトを生成して返します。 シンボリックリンクに関してリンクそのものの情報を返します。 lstat(2) を実装していないシステムでは、IO#statと同じです。

...ファイルの状態を含む File::Stat オブジェクトを生成して返します。
シンボリックリンクに関してリンクそのものの情報を返します。
lstat(2) を実装していないシステムでは、IO#statと同じです。

@raise Errno::EXXX 失敗した場合...
...ose されている場合に発生します。

//emlist[例][ruby]{
# testlink は testfile のシンボリックリンク
File
.open("testlink") do |f|
p f.lstat == File.stat("testfile") # => false
p f.stat == File.stat("testfile") # => true
end
//}

@see IO#stat, File.stat, File.lstat...

File#size -> Integer (24028.0)

ファイルのサイズを返します。

...ファイルのサイズを返します。

//emlist[例][ruby]{
File
.open("/dev/null") do |f|
f.size #=> 0
end
//}

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

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

@see File#lstat...

File#truncate(length) -> 0 (24028.0)

ファイルのサイズを最大 length バイトにします。

...書き込み用にオープンされていなければ発生します。

@raise Errno::EXXX サイズの変更に失敗した場合に発生します。

//emlist[例][ruby]{
IO.write("testfile", "1234567890")
File
.open("testfile", "a") do |f|
f.truncate(5) # => 0
f.size # => 5
end
//}...

File.delete(*filename) -> Integer (24028.0)

ファイルを削除します。削除したファイルの数を返します。 削除に失敗した場合は例外 Errno::EXXX が発生します。

...m filename ファイル名を表す文字列を指定します。

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

//emlist[例][ruby]{
IO.write("test.txt", "test")
p File.exist?("test.txt") # => true
p File.delete("test.txt") # => 1
p File.exist?("test.txt") # => false
begin
File
....
...delete("test.txt")
rescue
p $! # => #<Errno::ENOENT: No such file or directory @ unlink_internal - test.txt>
end
//}...

絞り込み条件を変える

File.rename(from, to) -> 0 (24028.0)

ファイルの名前を変更します。ディレクトリが異なる場合には移動も行い ます。rename(2) を参照してください。移動先のファ イルが存在する時には上書きされます。

...{
begin
File
.rename("testfile", "testfile.bak") # => 0
File
.rename("testfile", "testfile.bak")
rescue
# 2回目の rename 時にすでに testfile が存在しないため例外が発生する
$! # => #<Errno::ENOENT: No such file or directory @ rb_file_s_rename - (testfile, testfile.bak)>...

File.unlink(*filename) -> Integer (24028.0)

ファイルを削除します。削除したファイルの数を返します。 削除に失敗した場合は例外 Errno::EXXX が発生します。

...m filename ファイル名を表す文字列を指定します。

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

//emlist[例][ruby]{
IO.write("test.txt", "test")
p File.exist?("test.txt") # => true
p File.delete("test.txt") # => 1
p File.exist?("test.txt") # => false
begin
File
....
...delete("test.txt")
rescue
p $! # => #<Errno::ENOENT: No such file or directory @ unlink_internal - test.txt>
end
//}...