Ruby File classes and methods
File Represents a stdio object connected to a normal file. open returns an instance of this class for ordinary files.
Class Method
Serial Number | Method & Description |
---|---|
1 | File::atime(path) Returns the last access time of path. |
2 | File::basename( path[, suffix]) Returns the file at the end of path name. If suffix is specified, it is removed from the end of the file name. For example: File.basename("/home/users/bin/ruby.exe") #=> "ruby.exe" |
3 | File::blockdev?(path) Returns true if path is a block device. |
4 | File::chardev?(path) Returns true if path is a character device. |
5 | File::chmod(mode, path...) Change the permission mode of the specified file. |
6 | File::chown(owner, group, path...) Change the owner and ownership of the specified file Group. |
7 | File::ctime( path) Returns the last inode change time of path. |
8 | File::delete( path...) File::unlink( path...) Delete the specified file. |
9 | File::directory?(path) Returns true if path is a directory. |
10 | File::dirname( path) Returns the directory portion of path, excluding the final file name. |
11 | File::executable?(path) Returns true if path is executable. |
12 | File::executable_real?(path) Returns if path is executable with real user permissions true. |
13 | File::exist?(path) Returns true if path exists. |
1 | File::expand_path(path[, dir]) Returns the absolute path of path, expansion~ is owned by the process The user's home directory, ~user is the user's home directory. Relative paths are relative to the directory specified by dir, or the current working directory if dir is omitted. |
14 | File::file?(path) Returns true if path is an ordinary file. |
15 | File::ftype(path) Returns one of the following strings, indicating the file type:
|
16 | File::grpowned?(path) If path is owned by the user's group , then returns true. |
17 | File::join(item...) Returns a string joined together by the specified items , and use File::Separator to separate. For example: File::join("", "home", "usrs", "bin") # => "/home/usrs/bin" |
18 | File::link(old, new) Create a hard link to file old. |
19 | File::lstat( path) Same as stat, but it returns information on its own symbolic link instead is not the file pointed to. |
20 | File::mtime(path) Returns the last modification time of path. |
21 | File::new( path[, mode="r"]) File::open( path[, mode= "r"]) File::open( path[, mode="r"]) {|f| ...} Open the file. If a block is specified, the block is executed by passing the new file as argument. When the block exits, the file is automatically closed. These methods differ from Kernel.open in that even if path begins with |, subsequent strings will not be run as commands. |
22 | File::owned?(path) Returns true if path is owned by a valid user. |
23 | File::pipe?(path) Returns true if path is a pipe. |
24 | File::readable?(path) Returns true if path is readable. |
25 | File::readable_real?(path) Returns if path is readable with real user permissions true. |
25 | File::readlink(path) Returns the file pointed to by path. |
26 | File::rename(old, new) Change the file name old to new. |
27 | File::setgid?(path) If the set-group-id permission bit of path is set, then Return true. |
28 | File::setuid?(path) If the set-user-id permission bit of path is set, then Return true. |
29 | File::size(path) Returns the file size of path. |
30 | File::size?(path) Returns the file size of path, or nil if it is 0. |
31 | File::socket?(path) Returns true if path is a socket. |
32 | File::split(path) Returns an array containing the contents of path, which is split into File:: dirname(path) and File::basename(path). |
33 | File::stat( path) Returns a File::Stat object with information on path. |
34 | File::sticky?(path) Returns true if path's sticky bit is set. |
35 | File::symlink(old, new) Creates a symbolic link pointing to file old. |
36 | File::symlink?(path) Returns true if path is a symbolic link. |
37 | File::truncate( path, len) Truncate the specified file to len bytes. |
38 | File::unlink( path...) Deletes the file given by path. |
39 | File::umask([mask]) If no parameters are specified, the current umask is returned for the process . If an argument is specified, the umask is set and the old umask is returned. |
40 | File::utime( atime, mtime, path...) Change the access and modification time of the specified file . |
41 | File::writable?(path) Returns true if path is writable. |
42 | File::writable_real?(path) Returns if path is writable with real user permissions true. |
43 | File::zero?(path) Returns true if the file size of path is 0. |
Instance method
Assume f is an instance of the File class:
Serial number | Method & Description |
---|---|
1 | f.atime Return The last access time of f. |
2 | f.chmode(mode) Change the permission mode of f. |
3 | f.chown(owner, group) Change the owner and group of f. |
4 | f.ctime Returns the last inode change time of f. |
5 | f.flock( op) Call flock(2). op can be 0 or a logical value or the File class constants LOCK_EX, LOCK_NB, LOCK_SH, and LOCK_UN. |
6 | f.lstat Same as stat, but it returns information on its own symbolic link rather than the one it points to document. |
7 | f.mtime Returns the last modification time of f. |
8 | f.path Returns the pathname used to create f. |
9 | f.reopen( path[, mode="r"]) Reopen the file. |
10 | f.truncate(len) Truncate f to len bytes. |