The file access class, normally created by open or File.open.
Open file objects that cannot be referenced will be closed and discarded by the next garbage collection.
Returns the file's last modified time (Time object).
If time retrieval fails, throws an Errno::EXXX exception.
Returns the final slash-delimited component of filename. If suffix is supplied and is identical to the end of filename, filename is returned without the suffix.
p File.basename("ruby/ruby.c") # => "ruby.c" p File.basename("ruby/ruby.c", ".c") # => "ruby" p File.basename("ruby/ruby.c", ".*") # => "ruby" p File.basename("ruby/ruby.exe", ".*") # => "ruby"
Also see File.dirname and File.extname.
Deletes a file or files and returns the number of files deleted. If deletion fails, throws an Errno::EXXX exception.
This method is for file deletion and cannot delete directories.
Returns all but the final slash-delimited component of filename as a string. Returns "." (the current directory) for a filename that does not include a slash.
p File.dirname("dir/file.ext") # => "dir" p File.dirname("file.ext") # => "." p File.dirname("foo/bar/") # => "foo" p File.dirname("foo//bar") # => "foo"
Also see File.basename and File.extname.
Returns a string containing path's expanded absolute path. If path is relative, sets default_dir as the base directory. If default_dir is nil or missing, uses the current directory.
p File.expand_path("..") # => "/home/matz/work" p File.expand_path("..", "/tmp") # => "/"
Returns filename's extension (the string after the final dot). Dots in directory names or at the start of filenames are not considered to be denoting extensions. If filename contains no extension, returns an empty string.
p File.extname("foo/foo.txt") # => ".txt" p File.extname("foo/foo.tar.gz") # => ".gz" p File.extname("foo/bar") # => "" p File.extname("foo/.bar") # => "" p File.extname("foo.txt/bar") # => "" p File.extname(".foo") # => ""
Also see File.basename and File.dirname.
Opens the file specified by path and returns the file object. If file opening fails, throws an Errno::EXXX exception.
The mode argument is identical to the built-in function open.
Blocks can be specified for open(). When called with a block, executes the block with the given file object. The file will be closed automatically after executing the block.
When a block is specified, the return value of this method is the result of the block's execution.
Renames the file, moving it to a different directory as required. If a file already exists at the destination, it is overwritten.
Returns 0 if file movement is successful. Throws an Errno::EXXX exception if it fails.
Returns the time when the file was last modified (Time object).
Throws an Errno::EXXX exception if time retrieval fails.
Returns the path of the opened file.