From: Charles Hixson Date: 2001-09-22T02:58:21+09:00 Subject: [ruby-talk:21496] Problem with directory? Re: Path walking on windows Ed Sinjiashvili wrote: > Hi, > ... > -- Ed Sinjiashvili > Thanks immensely for this code snippet. I'm quite new to Ruby, so I probably couldn't have done this, and I certainly wouldn't have trusted the code when I ran into problems. > class Dir def walk (prefix = nil, &walker) e = self.entries e.delete "."; e.delete ".." if prefix e.collect! {|x| File.join(prefix, x) } end if block_given? e.each {|x| if File.directory? x then Dir.new(x).walk x, &walker else puts "#{x} is not a directory." end yield x } end nil end end Dir.new(tip_root).walk {|p| puts p } # if p =~ /\.([Hh][Tt][Mm]([Ll])?)$/ } This code simply lists all files in the directory. Even the included directories are shown as "is not a directory". And no descent into the sub-directories is attempted (naturally). I am running ruby 1.6.4 (2001-06-04) [i386-cygwin] on a Win95 4.00.950 B computer. I'd try the more recent version, but it won't compile on my computer with the current version of cygwin installed. -- Charles Hixson Copy software legally, the GNU way! Use GNU software, and legally make and share copies of software. See http://www.gnu.org http://www.redhat.com http://www.linux-mandrake.com http://www.calderasystems.com/ http://www.linuxapps.com/