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