Serial number Method and description 1 2 3 4 5 6 7 8 9 10 11 Hypothetical Serial number Method & description 1 2 3 4 5 6 7 8 9 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. 6.29.1. Class method #
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 Dir::chdir( path) Change the current directory. Dir::chroot( path) Change the root directory (only superusers are allowed). It is not available on all platforms. Dir::delete( path) delete path the specified directory. The directory must be empty. Dir::entries( path) Returns an array containing directories path the file name in the. Dir::foreach( path) {| f| ...} for path each file in the specified directory executes the block once. Dir::getwd Dir::pwd Return to the current directory. Dir::mkdir( path[, mode=0777]) Create path the specified directory.The permission mode can be used File::umask will be ignored on Win32 platforms. 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. Dir::pwd see Dir::getwd. Dir::rmdir( path) Dir::unlink( path) Dir::delete( path) Deletes the directory specified by path. The directory must be empty. 6.29.2. Example method #
d is an instance of Dir class: d.close Close the directory stream. d.each {| f| ...} Execute the block once for each entry in d. d.pos d.tell Returns the current position in d. d.pos= offset Sets the location in the directory stream. d.pos= pos d.seek(pos) Move to a location in d. Pos must be a value or 0 returned by d.pos. d.read Returns the next entry for d. d.rewind Move the position in d to the first entry. d.seek(po s) see also d.pos=pos . d.tell see also d.pos .