Win32 file stat and find conflict

I have a small snippet of code to recurse a directory which works as it
should

require 'find'

Find::find('C:\test') do |f|
  p f
end

When I change it like this

require 'win32/file/stat'
require 'find'

Find::find('C:\test') do |f|
  p f
end

Only the 'C:\test' directory is printed. None of the files or
subdirectories show up.

Any ideas on how to fix this?

thanks,

Luis

lrlebron@gmail.com wrote:

I have a small snippet of code to recurse a directory which works as it
should

require 'find'

Find::find('C:\test') do |f|
  p f
end

When I change it like this

require 'win32/file/stat'
require 'find'

Find::find('C:\test') do |f|
  p f
end

Only the 'C:\test' directory is printed. None of the files or
subdirectories show up.

Any ideas on how to fix this?

Don't require 'win32/file/stat' directly. Require win32-file instead, which will, in turn, require win32-file-stat.

The reason is that the 'find' module is calling File.lstat internally, which is just a pass through method to File::Stat. For it to work properly you need to use the File.lstat method that I've defined in the win32-file package.

I've updated the README file for win32-file-stat to explain the situation in a little more detail (and added a warning that you should never require win32-file-stat directly).

Regards,

Dan

# When I change it like this

···

From: lrlebron@gmail.com [mailto:lrlebron@gmail.com]:
#
# require 'win32/file/stat'
# require 'find'
#
# Find::find('C:\test') do |f|
# p f
# end
#
# Only the 'C:\test' directory is printed. None of the files or
# subdirectories show up.
#
# Any ideas on how to fix this?

cannot help you, but, i can also second that behavior here.
wish there was something like "unrequire" the "require"d

maybe something like,

require 'win32/file/stat'
begin
  test_require 'win32/file/stat'
rescue
  require 'win32/file/stat' :uninstall => true
end

:slight_smile:

kind regards -botp

# thanks,
# Luis