Daniel Berger
11/2/2006 5:27:00 PM
Oliver wrote:
> Hi Dan -
>
> Find.find(some path) do |path|
> puts path
> ...
> end
>
> suppose to loop all the files and sub directories, this is not the case
> once import win32/file, the only print out I can get is the very top
> level directory I pass in: say, if I run ruby test.rb -d "c:\temp",
> then the only print out is "c:\temp", all files in that directory are
> ignored. It should be pretty easy to verify. It almost seems like find
> module has a dependency on File module, and win32/file is in odd with
> it.
Aha! The culprit appears to be lstat. In the find module you'll see
this line:
if File.lstat(file).directory? then
That returns nil when you include win32-file:
irb(main):001:0> dir = "C:\\TMP"
=> "C:\\TMP"
irb(main):002:0> File.lstat(dir)
=> #<File::Stat dev=0x2, ino=0, mode=040755, nlink=1, uid=0, gid=0,
rdev=0x2, size=0, blksize=nil, blocks=nil, atime=Thu
Nov 02 09:56:43 -0700 2006, mtime=Fri Oct 21 09:47:09 -0600 2005,
ctime=Fri Oct 21 09:47:09 -0600 2005>
irb(main):003:0> File.lstat(dir).directory?
=> true
irb(main):004:0> require 'win32/file'
=> true
irb(main):005:0> File.lstat(dir).directory?
=> nil
I didn't reallize lstat was implemented on Windows. I'm guessing it's
an alias, so I'll need to check the source. But, that's definitely a
bug in win32-file (or rather, win32-file-stat).
I'll get this fixed and put out a release asap.
Thanks,
Dan