Ruby File Functions
EditRocket provides the following information on File functions in the Ruby source code builder.
atime(file_name) - Returns the last access time for the named file as a Time object).
atime(file_name) - Returns the last access time for the named file as a Time object).
basename(file_name [, suffix] ) - Returns the last component of the filename given in file_name, which must be formed using forward slashes (``/'') regardless of the separator used on the local file system. If suffix is given and present at the end of file_name, it is removed.
blockdev?(file_name) - Returns true if the named file is a block device.
catname(from, to) - If to is a valid directory, from will be appended to to, adding and escaping backslashes as necessary. Otherwise, to will be returned. Useful for appending from to to only if the filename was not specified in to.
chardev?(file_name) - Returns true if the named file is a character device.
chmod(mode, *files) - Changes permission bits on files to the bit pattern represented by mode. If the last parameter isn't a String, verbose mode will be enabled.
chmod(mode, *files) - Changes permission bits on files to the bit pattern represented by mode. If the last parameter isn't a String, verbose mode will be enabled.
chown(owner_int, group_int, file_name,... ) - Changes the owner and group of the named file(s) to the given numeric owner and group id's. Only a process with superuser privileges may change the owner of a file. The current owner of a file may change the file's group to any group to which the owner belongs. A nil or -1 owner or group id is ignored. Returns the number of files processed.
chown(owner_int, group_int, file_name,... ) - Changes the owner and group of the named file(s) to the given numeric owner and group id's. Only a process with superuser privileges may change the owner of a file. The current owner of a file may change the file's group to any group to which the owner belongs. A nil or -1 owner or group id is ignored. Returns the number of files processed.
compare(from, to, verbose = false) - Returns true if and only if the contents of files from and to are identical. If verbose is true, from <=> to is printed.
copy(from, to, verbose = false) - "Copies a file from to to using #syscopy. If to is a directory, copies from to to/from. If verbose is true, from -> to is printed."
ctime(file_name) - Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself).
ctime(file_name) - Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself).
delete(file_name, ...) - Deletes the named files, returning the number of names passed as arguments. Raises an exception on any error. See also Dir::rmdir.
directory?(file_name) - Returns true if the named file is a directory, false otherwise.
dirname(file_name ) - Returns all components of the filename given in file_name except the last one. The filename must be formed using forward slashes (``/'') regardless of the separator used on the local file system.
executable?(file_name) - Returns true if the named file is executable by the effective user id of this process.
executable_real?(file_name) - Returns true if the named file is executable by the real user id of this process.
exist?(file_name) - Return true if the named file exists.
exists?(file_name) - Return true if the named file exists.
expand_path(file_name [, dir_string] ) - Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless dir_string is given, in which case it will be used as the starting point. The given pathname may start with a ``~'', which expands to the process owner's home directory (the environment variable HOME must be set correctly). ``~user'' expands to the named user's home directory.
extname(path) - Returns the extension (the portion of file name in path after the period).
file?(file_name) - Returns true if the named file exists and is a regular file.
flock(locking_constant ) - Locks or unlocks a file according to locking_constant (a logical or of the values in the table below). Returns false if File::LOCK_NB is specified and the operation would otherwise have blocked. Not available on all platforms.
fnmatch?( pattern, path, [flags] ) - "Returns true if path matches against pattern The pattern is not a regular expression; instead it follows rules similar to shell filename globbing. It may contain the following metacharacters:"
fnmatch( pattern, path, [flags] ) - "Returns true if path matches against pattern The pattern is not a regular expression; instead it follows rules similar to shell filename globbing. It may contain the following metacharacters:"
ftype(file_name) - Identifies the type of the named file; the return string is one of ``file'', ``directory'', ``characterSpecial'', ``blockSpecial'', ``fifo'', ``link'', ``socket'', or ``unknown''.
grpowned?(file_name) - Returns true if the named file exists and the effective group id of the calling process is the owner of the file. Returns false on Windows.
identical?(file_1, file_2) - Returns true if the named files are identical.
install(from, to, mode = nil, verbose = false) - If src is not the same as dest, copies it and changes the permission mode to mode. If dest is a directory, destination is dest/src. If mode is not set, default is used. If verbose is set to true, the name of each file copied will be printed.
join(string, ...) - Returns a new string formed by joining the strings using File::SEPARATOR.
lchmod(mode_int, file_name, ...) - Equivalent to File::chmod, but does not follow symbolic links (so it will change the permissions associated with the link, not the file referenced by the link). Often not available.
lchown(owner_int, group_int, file_name,..) - Equivalent to File::chown, but does not follow symbolic links (so it will change the owner associated with the link, not the file referenced by the link). Often not available. Returns number of files in the argument list.
link(old_name, new_name) - Creates a new name for an existing file using a hard link. Will not overwrite new_name if it already exists (raising a subclass of SystemCallError). Not available on all platforms.
lstat(file_name) - Same as File::stat, but does not follow the last symbolic link. Instead, reports on the link itself.
lstat(file_name) - Same as File::stat, but does not follow the last symbolic link. Instead, reports on the link itself.
makedirs(*dirs) - Creates a directory and all its parent directories. For example,
move(from, to, verbose = false) - "Moves a file from to to using #syscopy. If to is a directory, copies from from to to/from. If verbose is true, from -> to is printed."
mtime(file_name) - Returns the modification time for the named file as a Time object.
mtime(file_name) - Returns the modification time for the named file as a Time object.
new(filename, mode="r") - Opens the file named by filename according to mode (default is ``r'') and returns a new File object. See the description of class IO for a description of mode. The file mode may optionally be specified as a Fixnum by or-ing together the flags (O_RDONLY etc, again described under IO). Optional permission bits may be given in perm. These mode and permission bits are platform dependent; on Unix systems, see open(2) for details.
o_chmod(p1) - "Alias for #chmod"
owned?(file_name) - Returns true if the named file exists and the effective used id of the calling process is the owner of the file.
path - Returns the pathname used to create file as a string. Does not normalize the name.
pipe?(file_name) - Returns true if the named file is a pipe.
readable?(file_name) - Returns true if the named file is readable by the effective user id of this process.
readable_real?(file_name) - Returns true if the named file is readable by the real user id of this process.
readlink(link_name) - Returns the name of the file referenced by the given link. Not available on all platforms.
rename(old_name, new_name) - Renames the given file to the new name. Raises a SystemCallError if the file cannot be renamed.
safe_unlink(*files) - Removes a list of files. Each parameter should be the name of the file to delete. If the last parameter isn't a String, verbose mode will be enabled. Returns the number of files deleted.
setgid?(file_name) - Returns true if the named file has the setgid bit set.
setuid?(file_name) - Returns true if the named file has the setuid bit set.
size?(file_name) - Returns nil if file_name doesn't exist or has zero size, the size of the file otherwise.
size(file_name) - Returns the size of file_name.
socket?(file_name) - Returns true if the named file is a socket.
split(file_name) - Splits the given string into a directory and a file component and returns them in a two-element array. See also File::dirname and File::basename.
stat(file_name) - Returns a File::Stat object for the named file (see File::Stat).
sticky?(file_name) - Returns true if the named file has the sticky bit set.
symlink?(file_name) - Returns true if the named file is a symbolic link.
symlink(old_name, new_name) - Creates a symbolic link called new_name for the existing file old_name. Raises a NotImplemented exception on platforms that do not support symbolic links.
syscopy(from, to) - Copies a file from to to. If to is a directory, copies from to to/from.
truncate(file_name, integer) - Truncates the file file_name to be at most integer bytes long. Not available on all platforms.
truncate(file_name, integer) - Truncates the file file_name to be at most integer bytes long. Not available on all platforms.
umask() - Returns the current umask value for this process. If the optional argument is given, set the umask to that value and return the previous value. Umask values are subtracted from the default permissions, so a umask of 0222 would make a file read-only for everyone.
unlink(file_name, ...) - Deletes the named files, returning the number of names passed as arguments. Raises an exception on any error. See also Dir::rmdir.
utime(atime, mtime, file_name,...) - Sets the access and modification times of each named file to the first two arguments. Returns the number of file names in the argument list.
writable?(file_name) - Returns true if the named file is writable by the effective user id of this process.
writable_real?(file_name) - Returns true if the named file is writable by the real user id of this process.
zero?(file_name) - Returns true if the named file exists and has a zero size.