Forum: Ruby File.fnmatch? doesn't distinguish between .filename and ./filename ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Stefano C. (Guest)
on 2008-11-14 12:52
(Received via mailing list)
I know that File.fnmatch? returns false for file names starting with a
unless you specify the File::FNM_DOTMATCH argument. The reason is that
starting with a dot are hidden files and so you (usually) don't want to
them into account.

However, I just discovered that it also returns false for file names
in ./ , for example ./xyz.rb. I think this behaviour is wrong: this
isn't a
hidden file, but a common file in the current directory. This can lead
unexpected (in my opinion) results. For example, look at this code:

require 'find'
Find.find('.'){|f| puts f if File.fnmatch('*.rb', f)}

Since Find.find passes to the block filenames starting with ./ , no
regardless of their extension, will be matched by fnmatch. This is not
most people expects. To make the above work, I'd either have to pass the
File::FNM_DOTMATCH to the fnmatch (which would have the unwanted side
of also matching hidden files) or to manually remove the leading dot
from the
file name.

What do others think?

This topic is locked and can not be replied to.