static public Method

Dir.foreach(p1)

Dir.foreach( dirname ) {| filename | block }   nil

Calls the block once for each entry in the named directory, passing the filename of each entry as a parameter to the block.

Dir.foreach("testdir") {|x| puts "Got #{x}" }

produces:

Got .
Got ..
Got config.h
Got main.rb

Source Code

/*
*  call-seq:
*     Dir.foreach( dirname ) {| filename | block }  => nil
*
*  Calls the block once for each entry in the named directory, passing
*  the filename of each entry as a parameter to the block.
*
*     Dir.foreach("testdir") {|x| puts "Got #{x}" }
*
*  <em>produces:</em>
*
*     Got .
*     Got ..
*     Got config.h
*     Got main.rb
*
*/
static VALUE
dir_foreach(io, dirname)
   VALUE io, dirname;
{
   VALUE dir;

   dir = dir_open_dir(dirname);
   rb_ensure(dir_each, dir, dir_close, dir);
   return Qnil;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.