D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Dir
/
Filename :
cdesc-Dir.ri
back
Copy
U:RDoc::NormalClass[iI"Dir:ET@I"Object;To:RDoc::Markup::Document:@parts[o;;[ : @fileI" dir.c;T:0@omit_headings_from_table_of_contents_below0o;;[9o:RDoc::Markup::Paragraph;[I"RAn object of class \Dir represents a directory in the underlying file system.;To:RDoc::Markup::BlankLine o;;[I"It consists mainly of:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o;;[I"8A string _path_, given when the object is created, ;TI"?that specifies a directory in the underlying file system; ;TI"#method #path returns the path.;To;;0;[o;;[ I"0A collection of string <i>entry names</i>, ;TI"Ueach of which is the name of a directory or file in the underlying file system; ;TI"&the entry names may be retrieved ;TI"@in an {array-like fashion}[rdoc-ref:Dir@Dir+As+Array-Like] ;TI"Dor in a {stream-like fashion}[rdoc-ref:Dir@Dir+As+Stream-Like].;T@S:RDoc::Markup::Heading: leveli: textI"About the Examples;T@o;;[I":Some examples on this page use this simple file tree:;T@o:RDoc::Markup::Verbatim;[I"example/ ;TI"├── config.h ;TI"├── lib/ ;TI"│ ├── song/ ;TI"&│ │ └── karaoke.rb ;TI"│ └── song.rb ;TI"└── main.rb ;T:@format0o;;[I"&Others use the file tree for the ;TI"9{Ruby project itself}[https://github.com/ruby/ruby].;T@S;;i;I"\Dir As \Array-Like;T@o;;[I".A \Dir object is in some ways array-like:;T@o; ;;;[o;;0;[o;;[I"?It has instance methods #children, #each, and #each_child.;To;;0;[o;;[I"HIt includes {module Enumerable}[rdoc-ref:Enumerable@What-27s+Here].;T@S;;i;I"\Dir As Stream-Like;T@o;;[I"/A \Dir object is in some ways stream-like.;T@o;;[ I"/The stream is initially open for reading, ;TI"7but may be closed manually (using method #close), ;TI"Rand will be closed on block exit if created by Dir.open called with a block. ;TI"7The closed stream may not be further manipulated, ;TI"and may not be reopened.;T@o;;[I"RThe stream has a _position_, which is the index of an entry in the directory:;T@o; ;;;[o;;0;[o;;[I";The initial position is zero (before the first entry).;To;;0;[o;;[I":\Method #tell (aliased as #pos) returns the position.;To;;0;[o;;[I"O\Method #pos= sets the position (but ignores a value outside the stream), ;TI"and returns the position.;To;;0;[o;;[I"O\Method #seek is like #pos=, but returns +self+ (convenient for chaining).;To;;0;[o;;[I"Q\Method #read, if not at end-of-stream, reads the next entry and increments ;TI"the position; ;TI":if at end-of-stream, does not increment the position.;To;;0;[o;;[I"/\Method #rewind sets the position to zero.;T@o;;[I"NExamples (using the {simple file tree}[rdoc-ref:Dir@About+the+Examples]):;T@o;;[I"2dir = Dir.new('example') # => #<Dir:example> ;TI"%dir.pos # => 0 ;TI" ;TI"dir.read # => "." ;TI"dir.read # => ".." ;TI"dir.read # => "config.h" ;TI"dir.read # => "lib" ;TI"dir.read # => "main.rb" ;TI"dir.pos # => 5 ;TI"dir.read # => nil ;TI"dir.pos # => 5 ;TI" ;TI"$dir.rewind # => #<Dir:example> ;TI"dir.pos # => 0 ;TI" ;TI"dir.pos = 3 # => 3 ;TI"dir.pos # => 3 ;TI" ;TI"%dir.seek(4) # => #<Dir:example> ;TI"dir.pos # => 4 ;TI" ;TI"dir.close # => nil ;TI"!dir.read # Raises IOError. ;T;0S;;i;I"What's Here;T@o;;[I"*First, what's elsewhere. \Class \Dir:;T@o; ;;;[o;;0;[o;;[I"AInherits from {class Object}[rdoc-ref:Object@What-27s+Here].;To;;0;[o;;[I"FIncludes {module Enumerable}[rdoc-ref:Enumerable@What-27s+Here], ;TI"1which provides dozens of additional methods.;T@o;;[I";Here, class \Dir provides methods that are useful for:;T@o; ;;;[ o;;0;[o;;[I"${Reading}[rdoc-ref:Dir@Reading];To;;0;[o;;[I"${Setting}[rdoc-ref:Dir@Setting];To;;0;[o;;[I"&{Querying}[rdoc-ref:Dir@Querying];To;;0;[o;;[I"({Iterating}[rdoc-ref:Dir@Iterating];To;;0;[o;;[I" {Other}[rdoc-ref:Dir@Other];T@S;;i;I"Reading;T@o; ;;;[ o;;0;[o;;[I"4#close: Closes the directory stream for +self+.;To;;0;[o;;[I"A#pos=: Sets the position in the directory stream for +self+.;To;;0;[o;;[I"P#read: Reads and returns the next entry in the directory stream for +self+.;To;;0;[o;;[I"V#rewind: Sets the position in the directory stream for +self+ to the first entry.;To;;0;[o;;[I"A#seek: Sets the position in the directory stream for +self+ ;TI"#the entry at the given offset.;T@S;;i;I"Setting;T@o; ;;;[o;;0;[o;;[I"C::chdir: Changes the working directory of the current process ;TI"to the given directory.;To;;0;[o;;[I"D::chroot: Changes the file-system root for the current process ;TI"to the given directory.;T@S;;i;I" Querying;T@o; ;;;[o;;0;[o;;[I"<::[]: Same as ::glob without the ability to pass flags.;To;;0;[o;;[I";::children: Returns an array of names of the children ;TI":(both files and directories) of the given directory, ;TI"1but not including <tt>.</tt> or <tt>..</tt>.;To;;0;[o;;[I"D::empty?: Returns whether the given path is an empty directory.;To;;0;[o;;[I":::entries: Returns an array of names of the children ;TI":(both files and directories) of the given directory, ;TI"*including <tt>.</tt> and <tt>..</tt>.;To;;0;[o;;[I"=::exist?: Returns whether the given path is a directory.;To;;0;[o;;[I"R::getwd (aliased as #pwd): Returns the path to the current working directory.;To;;0;[o;;[I"Q::glob: Returns an array of file paths matching the given pattern and flags.;To;;0;[o;;[I"R::home: Returns the home directory path for a given user or the current user.;To;;0;[o;;[I":#children: Returns an array of names of the children ;TI"-(both files and directories) of +self+, ;TI"1but not including <tt>.</tt> or <tt>..</tt>.;To;;0;[o;;[I"=#fileno: Returns the integer file descriptor for +self+.;To;;0;[o;;[I"I#path (aliased as #to_path): Returns the path used to create +self+.;To;;0;[o;;[I";#tell (aliased as #pos): Returns the integer position ;TI"(in the directory stream for +self+.;T@S;;i;I"Iterating;T@o; ;;;[ o;;0;[o;;[I"Q::each_child: Calls the given block with each entry in the given directory, ;TI"1but not including <tt>.</tt> or <tt>..</tt>.;To;;0;[o;;[I"N::foreach: Calls the given block with each entry in the given directory, ;TI"*including <tt>.</tt> and <tt>..</tt>.;To;;0;[o;;[I"=#each: Calls the given block with each entry in +self+, ;TI"*including <tt>.</tt> and <tt>..</tt>.;To;;0;[o;;[I"C#each_child: Calls the given block with each entry in +self+, ;TI"1but not including <tt>.</tt> or <tt>..</tt>.;T@S;;i;I" Other;T@o; ;;;[ o;;0;[o;;[I"O::mkdir: Creates a directory at the given path, with optional permissions.;To;;0;[o;;[I"J::new: Returns a new \Dir for the given path, with optional encoding.;To;;0;[o;;[I"S::open: Same as ::new, but if a block is given, yields the \Dir to the block, ;TI" closing it upon block exit.;To;;0;[o;;[I"M::unlink (aliased as ::delete and ::rmdir): Removes the given directory.;To;;0;[o;;[I"6#inspect: Returns a string description of +self+.;T; I"dir.rb;T; 0o;;[ ; I"lib/tmpdir.rb;T; 0; 0; 0[ [ [[I"Enumerable;To;;[ ; @ ; 0I" dir.c;T[[I" class;T[[:public[[I"[];TI"dir.rb;T[I" chdir;T@[I" children;T@[I"chroot;T@[I"delete;T@[I"each_child;T@[I"empty?;T@[I"entries;T@[I"exist?;T@[I"fchdir;T@[I"for_fd;T@[I"foreach;T@[I" getwd;T@[I" glob;T@�[I" home;T@[I" mkdir;T@[I" mktmpdir;TI"lib/tmpdir.rb;T[I"new;T@�[I" open;T@�[I"pwd;T@[I" rmdir;T@[I"tmpdir;T@�[I"unlink;T@[:protected[ [:private[ [I" instance;T[[;[[I" chdir;T@[I" children;T@[I" close;T@[I" each;T@[I"each_child;T@[I"fileno;T@[I"inspect;T@[I" path;T@[I"pos;T@[I" pos=;T@[I" read;T@[I"rewind;T@[I" seek;T@[I" tell;T@[I"to_path;T@[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ; 0; 0[ @ @tI"lib/cgi/session.rb;TI"lib/tempfile.rb;T@w@wcRDoc::TopLevel