Ruby Dir classes and methods
Dir
is a directory stream that represents a file name in a directory in the operating system. Dir
classes also have directory-related operations, such as matching wildcard file names, changing working directories, and so on.
Class method
Serial number |
Method and description |
1 |
Dir[pat] Dir::glob( pat) Returns an array containing the specified wildcard pattern pat matching file name: * -match contains null any string of a string ** -Recursively match any string ? -match any single character [...] -matches any of the closed characters {a,b...} -matches any one of the strings Dir["foo.*"] # Match "foo.c"、 "foo.rb" etc., Dir["foo.?"] # Match "foo.c"、 "foo.h" Wait
|
2 |
Dir::chdir( path) Change the current directory.
|
3 |
Dir::chroot( path) Change the root directory (only superusers are allowed). It is not available on all platforms.
|
4 |
Dir::delete( path) delete path the specified directory. The directory must be empty.
|
5 |
Dir::entries( path) Returns an array containing directories path the file name in the.
|
6 |
Dir::foreach( path) {| f| ...} for path each file in the specified directory executes the block once.
|
7 |
Dir::getwd Dir::pwd Return to the current directory.
|
8 |
Dir::mkdir( path[, mode=0777]) Create path the specified directory.The permission mode can be used File::umask will be ignored on Win32 platforms.
|
9 |
Dir::new( path) Dir::open( path) Dir::open( path) {| dir| ...} Return path gets or sets the new directory object of If open given a block, the new directory object is passed to the block, andthe block closes the directory object before terminating.
|
10 |
Dir::pwd see Dir::getwd.
|
11 |
Dir::rmdir( path) Dir::unlink( path) Dir::delete( path) Deletes the directory specified by path. The directory must be empty.
|
Example method
Hypothetical d
is an instance of Dir
class:
Serial number |
Method & description |
1 |
d.close Close the directory stream.
|
2 |
d.each {| f| ...} Execute the block once for each entry in d.
|
3 |
d.pos d.tell Returns the current position in d.
|
4 |
d.pos= offset Sets the location in the directory stream.
|
5 |
d.pos= pos d.seek(pos) Move to a location in d. Pos must be a value or 0 returned by d.pos.
|
6 |
d.read Returns the next entry for d.
|
7 |
d.rewind Move the position in d to the first entry.
|
8 |
d.seek(po s) see also d.pos=pos .
|
9 |
d.tell see also d.pos .
|