Name
Dir — Directory class
Synopsis
A Dir
is a class to
represent a directory stream that gives filenames in the directory in
the operating system. Dir
class also holds
directory related operations, such as wild card filename matching,
changing current working directory, etc. as class methods
Included Module
Enumerable
Class Methods
Dir[pat]
Dir::glob(
pat
)
Returns an array of filenames matching the specified wildcard pattern
pat
:*
Matches any string including the null string
**
Matches any string recursively
?
Matches any single character
[...]
Matches any one of enclosed characters
{a,b...}
Matches any one of strings
Dir["foo.*"] # matches "foo.c", "foo.rb", etc. Dir["foo.?"] # matches "foo.c", "foo.h", etc. Dir["*.[ch]"] # matches "main.c", "ruby.h", etc. Dir["*.{rb,c}"] # matches "main.c", "config.rb", etc. Dir["**/*.c"] # recursively matches any ".c" file
Dir::chdir(
path
)
Changes the current directory.
Dir::chroot(
path
)
Changes the root directory (only allowed by super user). Not available on all platforms.
Dir::delete(
path
)
See
Dir::rmdir(
path
)
.Dir::entries(
path
)
Returns an array of filenames in directory path.
Dir::foreach(
path
) {|
f
|
...
}
Executes the block once for each file in the directory specified by path.
Dir::getwd
Dir::pwd
Returns the current directory.
Dir::glob(
pat
)
See
Dir[pat]
.Dir::mkdir(
path
[,
mode
=0777])
Creates the directory specified by
path
. Permissionmode
may be modified by the value ofFile::umask
and is ignored on Win32 platforms.Dir::new(
path
)
Dir::open(
path
)
Dir::open(
path
) {| ...
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.