Common implementation for SVCB-compatible resource records.
Returns the real (absolute) pathname of pathname in the actual filesystem. The real pathname doesn’t contain symlinks or useless dots.
If dir_string is given, it is used as a base directory for interpreting relative pathname instead of the current directory.
The last component of the real pathname can be nonexistent.
Returns all components of the filename given in file_name except the last one (after first stripping trailing separators). The filename can be formed using both File::SEPARATOR
and File::ALT_SEPARATOR
as the separator when File::ALT_SEPARATOR
is not nil
.
File.dirname("/home/gumby/work/ruby.rb") #=> "/home/gumby/work"
If level
is given, removes the last level
components, not only one.
File.dirname("/home/gumby/work/ruby.rb", 2) #=> "/home/gumby" File.dirname("/home/gumby/work/ruby.rb", 4) #=> "/"
With string object
given, returns true
if path
is a string path leading to a directory, or to a symbolic link to a directory; false
otherwise:
File.directory?('.') # => true File.directory?('foo') # => false File.symlink('.', 'dirlink') # => 0 File.directory?('dirlink') # => true File.symlink('t,txt', 'filelink') # => 0 File.directory?('filelink') # => false
Argument path
can be an IO
object.
Returns the real (absolute) pathname of self
in the actual filesystem.
Does not contain symlinks or useless dots, ..
and .
.
The last component of the real pathname can be nonexistent.
Returns system configuration directory.
This is typically "/etc"
, but is modified by the prefix used when Ruby was compiled. For example, if Ruby is built and installed in /usr/local
, returns "/usr/local/etc"
on other platforms than Windows.
On Windows, this always returns the directory provided by the system.
Returns system temporary directory; typically “/tmp”.
With string object
given, returns true
if path
is a string path leading to a directory, or to a symbolic link to a directory; false
otherwise:
File.directory?('.') # => true File.directory?('foo') # => false File.symlink('.', 'dirlink') # => 0 File.directory?('dirlink') # => true File.symlink('t,txt', 'filelink') # => 0 File.directory?('filelink') # => false
Argument path
can be an IO
object.
The path where gem executables are to be installed.
The path were rubygems plugins are to be installed.
Creates directories at the paths in the given list
(a single path or an array of paths); returns list
if it is an array, [list]
otherwise.
Argument list
or its elements should be interpretable as paths.
With no keyword arguments, creates a directory at each path
in list
by calling: Dir.mkdir(path, mode)
; see Dir.mkdir
:
FileUtils.mkdir(%w[tmp0 tmp1]) # => ["tmp0", "tmp1"] FileUtils.mkdir('tmp4') # => ["tmp4"]
Keyword arguments:
mode: mode
- also calls File.chmod(mode, path)
; see File.chmod
.
noop: true
- does not create directories.
verbose: true
- prints an equivalent command:
FileUtils.mkdir(%w[tmp0 tmp1], verbose: true) FileUtils.mkdir(%w[tmp2 tmp3], mode: 0700, verbose: true)
Output:
mkdir tmp0 tmp1 mkdir -m 700 tmp2 tmp3
Raises an exception if any path points to an existing file or directory, or if for any reason a directory cannot be created.
Related: FileUtils.mkdir_p
.
Creates directories at the paths in the given list
(a single path or an array of paths); returns list
if it is an array, [list]
otherwise.
Argument list
or its elements should be interpretable as paths.
With no keyword arguments, creates a directory at each path
in list
by calling: Dir.mkdir(path, mode)
; see Dir.mkdir
:
FileUtils.mkdir(%w[tmp0 tmp1]) # => ["tmp0", "tmp1"] FileUtils.mkdir('tmp4') # => ["tmp4"]
Keyword arguments:
mode: mode
- also calls File.chmod(mode, path)
; see File.chmod
.
noop: true
- does not create directories.
verbose: true
- prints an equivalent command:
FileUtils.mkdir(%w[tmp0 tmp1], verbose: true) FileUtils.mkdir(%w[tmp2 tmp3], mode: 0700, verbose: true)
Output:
mkdir tmp0 tmp1 mkdir -m 700 tmp2 tmp3
Raises an exception if any path points to an existing file or directory, or if for any reason a directory cannot be created.
Related: FileUtils.mkdir_p
.
Creates directories at the paths in the given list
(a single path or an array of paths), also creating ancestor directories as needed; returns list
if it is an array, [list]
otherwise.
Argument list
or its elements should be interpretable as paths.
With no keyword arguments, creates a directory at each path
in list
, along with any needed ancestor directories, by calling: Dir.mkdir(path, mode)
; see Dir.mkdir
:
FileUtils.mkdir_p(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"] FileUtils.mkdir_p('tmp4/tmp5') # => ["tmp4/tmp5"]
Keyword arguments:
mode: mode
- also calls File.chmod(mode, path)
; see File.chmod
.
noop: true
- does not create directories.
verbose: true
- prints an equivalent command:
FileUtils.mkdir_p(%w[tmp0 tmp1], verbose: true) FileUtils.mkdir_p(%w[tmp2 tmp3], mode: 0700, verbose: true)
Output:
mkdir -p tmp0 tmp1 mkdir -p -m 700 tmp2 tmp3
Raises an exception if for any reason a directory cannot be created.
FileUtils.mkpath
and FileUtils.makedirs
are aliases for FileUtils.mkdir_p
.
Related: FileUtils.mkdir
.
Creates directories at the paths in the given list
(a single path or an array of paths), also creating ancestor directories as needed; returns list
if it is an array, [list]
otherwise.
Argument list
or its elements should be interpretable as paths.
With no keyword arguments, creates a directory at each path
in list
, along with any needed ancestor directories, by calling: Dir.mkdir(path, mode)
; see Dir.mkdir
:
FileUtils.mkdir_p(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"] FileUtils.mkdir_p('tmp4/tmp5') # => ["tmp4/tmp5"]
Keyword arguments:
mode: mode
- also calls File.chmod(mode, path)
; see File.chmod
.
noop: true
- does not create directories.
verbose: true
- prints an equivalent command:
FileUtils.mkdir_p(%w[tmp0 tmp1], verbose: true) FileUtils.mkdir_p(%w[tmp2 tmp3], mode: 0700, verbose: true)
Output:
mkdir -p tmp0 tmp1 mkdir -p -m 700 tmp2 tmp3
Raises an exception if for any reason a directory cannot be created.
FileUtils.mkpath
and FileUtils.makedirs
are aliases for FileUtils.mkdir_p
.
Related: FileUtils.mkdir
.
Removes directories at the paths in the given list
(a single path or an array of paths); returns list
, if it is an array, [list]
otherwise.
Argument list
or its elements should be interpretable as paths.
With no keyword arguments, removes the directory at each path
in list
, by calling: Dir.rmdir(path)
; see Dir.rmdir
:
FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"] FileUtils.rmdir('tmp4/tmp5') # => ["tmp4/tmp5"]
Keyword arguments:
parents: true
- removes successive ancestor directories if empty.
noop: true
- does not remove directories.
verbose: true
- prints an equivalent command:
FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3], parents: true, verbose: true) FileUtils.rmdir('tmp4/tmp5', parents: true, verbose: true)
Output:
rmdir -p tmp0/tmp1 tmp2/tmp3 rmdir -p tmp4/tmp5
Raises an exception if a directory does not exist or if for any reason a directory cannot be removed.
Related: methods for deleting.
Removes directories at the paths in the given list
(a single path or an array of paths); returns list
, if it is an array, [list]
otherwise.
Argument list
or its elements should be interpretable as paths.
With no keyword arguments, removes the directory at each path
in list
, by calling: Dir.rmdir(path)
; see Dir.rmdir
:
FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"] FileUtils.rmdir('tmp4/tmp5') # => ["tmp4/tmp5"]
Keyword arguments:
parents: true
- removes successive ancestor directories if empty.
noop: true
- does not remove directories.
verbose: true
- prints an equivalent command:
FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3], parents: true, verbose: true) FileUtils.rmdir('tmp4/tmp5', parents: true, verbose: true)
Output:
rmdir -p tmp0/tmp1 tmp2/tmp3 rmdir -p tmp4/tmp5
Raises an exception if a directory does not exist or if for any reason a directory cannot be removed.
Related: methods for deleting.
The default directory for binaries