From: Charles Hixson Date: 2001-09-29T02:48:43+09:00 Subject: [ruby-talk:21810] Re: Problem with directory? Re: Path walking on windows Ed Sinjiashvili wrote: > Charles Hixson writes: > >>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'm sorry to answer so late but I was away for a while. The problem > with this code is that you don't give prefix dir to initial #walk > invocation. Dir class has a notion of working directory - you can > retrieve it with #pwd. #walk method never changes that class variable, > i.e. it does not #chdir into directories. Instead it receives prefix > parameter which is a relative path to current working directory. I > used to start from current dir - so I didn't pass "." to > walk. Following two calls are effectively equivalent: > Dir.new(".").walk "." {|p| puts p} > Dir.new(".").walk {|p| puts p} > > But if you don't start walking from current dir - you should always > pass relative prefix to #walk. It's a tradeoff of not changing working > directory. > Dir.new(tip_root).walk(tip_root) {|p| puts p } > > I hope this helps and I suggest you to try mswin32 port of ruby. As I > said in some previous post - it's way faster than cygwin . > > -- > Ed Sinjiashvili I don't think that's the answer. It found the directories, it just didn't recognize that they were directories rather than normal files. After I removed and re-installed CygWin, this problem went away. But I was using the version from Practical Programmers, rather than a version locally compiled. (Local compiles file to make because of some problem with dllwrap .. well, cygwin doesn't really support win95, so I can't really complain about that!) OTOH, the Ruby version from Practical Programmers does use the cygwin dll, so perhaps you mean some other version, that I don't know about. (There must be some reason that a replaced cygwin install could change the results!) Still, running under cygwin has many benefits, one of which is that I can capture the error stream to a text file, for perusal after it would have rolled off the top of the screen. And it doesn't determine which version of Ruby I run. If it matters, I also tried running under MSDos, and the same problem occured there. Which makes it doubly strange that an ab-initio install of CygWin should fix things. -- 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/