Ruby File
Class and Methods
File represents a stdio object connected to a regular file. open
returns an instance of this class for a regular file.
Class Methods
No. | Method & Description | ||
---|---|---|---|
1 | File::atime(path) <br>Returns the last access time for the path. |
||
2 | File::basename(path[, suffix]) <br>Returns the filename from the end of the path. If suffix is specified, it is removed from the end of the filename. <br>Example: File.basename("/home/users/bin/ruby.exe") #=> "ruby.exe" |
||
3 | File::blockdev?(path) <br>Returns true if the path is a block device. |
||
4 | File::chardev?(path) <br>Returns true if the path is a character device. |
||
5 | File::chmod(mode, path...) <br>Changes the permission mode of the specified files. |
||
6 | File::chown(owner, group, path...) <br>Changes the owner and group of the specified files. |
||
7 | File::ctime(path) <br>Returns the last inode change time for the path. |
||
8 | File::delete(path...) <br>File::unlink(path...) <br>Deletes the specified files. |
||
9 | File::directory?(path) <br>Returns true if the path is a directory. |
||
10 | File::dirname(path) <br>Returns the directory part of the path, excluding the final filename. |
||
11 | File::executable?(path) <br>Returns true if the path is executable. |
||
12 | File::executable_real?(path) <br>Returns true if the path is executable by the real user permissions. |
||
13 | File::exist?(path) <br>Returns true if the path exists. |
||
14 | File::expand_path(path[, dir]) <br>Returns the absolute path of the path, expanding ~ to the process owner's home directory and ~user to the user's home directory. Relative paths are relative to the directory specified by dir, or the current working directory if dir is omitted. |
||
15 | File::file?(path) <br>Returns true if the path is a regular file. |
||
16 | File::ftype(path) <br>Returns one of the following strings indicating the file type: file - regular file<br>directory - directory<br>characterSpecial - character special file<br>blockSpecial - block special file<br>fifo - named pipe (FIFO)<br>link - symbolic link<br>socket - Socket<br>unknown - unknown file type |
||
17 | File::grpowned?(path) <br>Returns true if the path is owned by the user's group. |
||
18 | File::join(item...) <br>Returns a string by joining the specified items together, separated by File::Separator . <br>Example: File::join("", "home", "usrs", "bin") # => "/home/usrs/bin" |
||
19 | File::link(old, new) <br>Creates a hard link to the file old. |
||
20 | File::lstat(path) <br>Same as stat , but it returns information about the symlink itself, not the file it points to. |
||
21 | File::mtime(path) <br>Returns the last modification time for the path. |
||
22 | File::new(path[, mode="r"]) <br>File::open(path[, mode="r"]) <br>`File::open(path[, mode="r"]) { |
f | ...}<br>Opens a file. If a block is specified, it is executed with the new file as a parameter. The file is automatically closed when the block exits. These methods differ from Kernel.open, even if the path starts with |`, the subsequent string will not be executed as a command. |
23 | File::owned?(path) <br>Returns true if the path is owned by the effective user. |
||
24 | File::pipe?(path) <br>Returns true if the path is a pipe. |
||
25 | File::readable?(path) <br>Returns true if the path is readable. |
||
26 | File::readable_real?(path) <br>Returns true if the path is readable by the real user permissions. |
||
27 | File::readlink(path) <br>Returns the file pointed to by the path. |
||
28 | File::rename(old, new) <br>Changes the filename old to new. |
||
29 | File::setgid?(path) <br>Returns true if the set-group-id permission bit is set for the path. |
||
30 | File::setuid?(path) <br>Returns true if the set-user-id permission bit is set for the path. |
||
31 | File::size(path) <br>Returns the file size of the path. |
||
32 | File::size?(path) <br>Returns the file size of the path, or nil if it is 0. |
||
33 | File::socket?(path) <br>Returns true if the path is a socket. |
||
34 | File::split(path) <br>Returns an array containing the path split into File::dirname(path) and File::basename(path) . |
||
35 | File::stat(path) <br>Returns a File::Stat object with information about the path. |
||
36 | File::sticky?(path) <br>Returns true if the sticky bit is set for the path. |
||
37 | File::symlink(old, new) <br>Creates a symbolic link to the file old. |
||
38 | File::symlink?(path) <br>Returns true if the path is a symbolic link. |
||
39 | File::truncate(path, len) <br>Truncates the specified file to len bytes. |
||
40 | File::unlink(path...) <br>Deletes the specified files. |
||
41 | File::umask([mask]) <br>Returns the current umask for the process if no argument is specified. If an argument is specified, it sets the umask and returns the old umask. |
||
42 | File::utime(atime, mtime, path...) <br>Changes the access and modification times of the specified files. |
||
43 | File::writable?(path) <br>Returns true if the path is writable. |
||
44 | File::writable_real?(path) <br>Returns true if the path is writable by the real user permissions. |
||
45 | File::zero?(path) <br>Returns true if the file size of the path is 0. |
Instance Methods
Assume f is an instance of the File class:
No. | Method & Description |
---|---|
1 | f.atime <br>Returns the last access time for f. |
2 | f.chmod(mode) <br>Changes the permission mode of f. |
3 | f.chown(owner, group) <br>Changes the owner and group of f. |
4 | f.ctime <br>Returns the last inode change time for f. |
5 | f.flock(op) <br>Calls flock(2) . op can be 0 or a logical value or File class constants LOCK_EX , LOCK_NB , LOCK_SH , and LOCK_UN . |
6 | f.lstat <br>Same as stat , but it returns information about the symlink itself, not the file it points to. |
7 | f.mtime <br>Returns the last modification time for f. |
8 | f.path <br>Returns the pathname used to create f. |
9 | f.reopen(path[, mode="r"]) <br>Reopens the file. |
10 | f.truncate(len) <br>Truncates f to len bytes. |