home PYTHONJAVA
 

Ruby File class and method

File represents an stdio object that is connected to a regular file. Open returns an instance of this class for a regular file.

class method

serial numbermethod & description
1File::atime( path)
Returns the last access time of path.
2File::basename( path[, suffix])
Returns the file name at the end of path. If suffix is specified, it will be removed from the end of the file name.
For example: File.basename("/home/users/bin/ruby.exe") #=> "ruby.exe"
3File::blockdev?( path)
Returns true if path is a block device.
4File::chardev?( path)
Returns true if path is a character device.
5File::chmod( mode, path...)
Change the permission mode of the specified file.
6File::chown( owner, group, path...)
Changes the owner and group of the specified file.
7File::ctime( path)
Returns the last inode change time of path.
8File::delete( path...)
File::unlink( path...)

Delete the specified file.
9File::directory?( path)
Returns true if path is a directory.
10File::dirname( path)
Returns the directory portion of path, excluding the last file name.
11File::executable?( path)
Returns true if path is executable.
12File::executable_real?( path)
Returns true if path is executable by real user rights.
13File::exist?( path)
Returns true if path exists.
1File::expand_path( path[, dir])
Returns the absolute path of path, extension ~ is the process owner's home directory , ~user is the user's home directory. The relative path is relative to the directory specified by dir, relative to the current working directory if dir is omitted.
14File::file?( path)
Returns true if path is a normal file.
15File::ftype( path)
Returns one of the following strings representing the file type:
  • file - normal file
  • directory - directory
  • characterSpecial - Character special file
  • blockSpecial - block special file
  • fifo - Named Pipes (FIFO)
  • link - symbolic link
  • socket - Socket
  • unknown - Unknown file type
16File::grpowned?( path)
Returns true if path is owned by the user's own group.
17File::join( item...)
Returns a string concatenated by the specified item and uses File ::Separator is separated.
For example: File::join("", "home", "usrs", "bin") # => "/home/usrs/bin"
18File::link( old, new)
Create a hard link to the file old.
19File::lstat( path)
Same as stat, but it returns information on its own symbolic link instead of pointing to file.
20File::mtime( path)
Returns the last modification time of path.
21File::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 a new file as a parameter. When the block exits, the file is automatically closed. These methods are different from Kernel.open, and even if path starts with |, subsequent strings will not run as commands.
22File::owned?( path)
Returns true if path is owned by a valid user.
23File::pipe?( path)
Returns true if path is a pipe.
24File::readable?( path)
Returns true if path is readable.
25File::readable_real?( path)
Returns true if path is readable by real user rights.
25File::readlink( path)
Returns the file pointed to by path.
26File::rename( old, new)
Change the file name old to new.
27File::setgid?( path)
Returns true if the set-group-id permission bit of path is set.
28File::setuid?( path)
Returns true if the set-user-id permission bit of path is set.
29File::size( path)
Returns the file size of path.
30File::size?( path)
Returns the file size of path, or 0 if it returns nil.
31File::socket?( path)
Returns true if path is a socket.
32File::split( path)
returns an array containing the contents of path, path is divided into File::dirname(path) And File::basename(path).
33File::stat( path)
Returns a File::Stat object with information on path.
34File::sticky?( path)
Returns true if the sticky bit of path is set.
35File::symlink( old, new)
Create a symbolic link to the file old.
36File::symlink?( path)
Returns true if path is a symbolic link.
37File::truncate( path, len)
Truncate the specified file to len bytes.
38File::unlink( path...)
Delete the file given by path.
39File::umask([ mask])
If no argument is specified, the current umask is returned for the process. If a parameter is specified, umask is set and the old umask is returned.
40File::utime( atime, mtime, path...)
Changes the access and modification time of the specified file.
41File::writable?( path)
Returns true if path is writable.
42File::writable_real?( path)
Returns true if path is writable by real user rights.
43File::zero?( path)
Returns true if the file size of path is 0.

Instance method

Assume that f is an instance of the File class:

serial numbermethod & description
1f.atime
Returns the last access time of f.
2f.chmode( mode)
Change the permission mode of f.
3f.chown( owner, group)
Change the owner and group of f.
4f.ctime
Returns the last inode change time of f.
5f.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.
6f.lstat
Same as stat, but it returns information on its own symbolic link, not the file it points to.
7f.mtime
Returns the last modification time of f.
8f.path
Returns the path name used to create f.
9f.reopen( path[, mode="r"])
Reopen the file.
10f.truncate( len)
Truncate f to len bytes.





welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.