foreach(p1)
public
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
Show source
/*
* 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;
RETURN_ENUMERATOR(io, 1, &dirname);
dir = dir_open_dir(dirname);
rb_ensure(dir_each, dir, dir_close, dir);
return Qnil;
}