home PYTHONJAVA
 

Ruby Dir class and method

Dir is a directory stream that represents the name of a file in the directory in the operating system. The Dir class also has directory-related operations, such as wildcard file name matching, changing the working directory, and so on.

class method

serial numbermethod & description
1Dir[pat]
Dir::glob( pat)

returns an array containing the filenames that match the specified wildcard pattern pat :
  • * - Matches any string containing a null string
  • ** - Recursively match any string
  • ? - Match any single character
  • [...] - Match any of the enclosed characters
  • {a,b...} - Match any of the strings
Dir["foo.*"] # matches "foo.c", "foo.rb", etc.
Dir["foo.?"] # matches "foo.c", "foo.h", etc.
2Dir::chdir( path)
Change the current directory.
3Dir::chroot( path)
Change the root directory (superusers only). Not available on all platforms.
4Dir::delete( path)
Delete the directory specified by path. The directory must be empty.
5Dir::entries( path)
returns an array containing the filenames in the directory path.
6Dir::foreach( path) {| f| ...}
Execute each file in the directory specified by path One block.
7Dir::getwd
Dir::pwd

returns the current directory.
8Dir::mkdir( path[, mode=0777])
Create the directory specified by path. Permission mode can be modified by the value of File::umask and will be ignored on Win32 platforms.
9Dir::new( path)
Dir::open( path)
Dir::open( path) {| dir| ...}

returns a new directory object for path . If open gives a block, the new directory object is passed to the block, and the block closes the directory object before terminating.
10Dir::pwd
See Dir::getwd.
11Dir::rmdir( path)
Dir::unlink( path)
Dir::delete( path)

Delete the directory specified by path. The directory must be empty.

Instance method

Assume that d is an instance of the Dir class:

serial numbermethod & description
1d.close
Close the directory stream.
2d.each {| f| ...}
Executes a block for each entry in d.
3d.pos
D.tell
returns the current position in d.
4d.pos=offset
Set the location in the directory stream.
5d.pos= pos
D.seek(pos)

moves to a location in d. Pos must be a value returned by d.pos or 0.
6d.read
Returns the next entry for d.
7d.rewind
Move the position in d to the first entry.
8d.seek(po s)
See d.pos=pos.
9d.tell
See d.pos.





welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.