# File.fnmatch? doesn't distinguish between .filename and ./filename?

**URL:** <https://www.ruby-forum.com/t/file-fnmatch-doesnt-distinguish-between-filename-and-filename/153288>\
**Category:** Ruby\
**Created:** [November 14, 2008, 11:52am UTC](https://www.ruby-forum.com/t/file-fnmatch-doesnt-distinguish-between-filename-and-filename/153288 "2008-11-14T11:52:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![crocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/fbc32d/32.png) [@crocco](https://www.ruby-forum.com/u/crocco)\
**Post date:** [November 14, 2008, 11:52am UTC](https://www.ruby-forum.com/t/file-fnmatch-doesnt-distinguish-between-filename-and-filename/153288/1 "2008-11-14T11:52:04Z")

</div>

I know that File.fnmatch? returns false for file names starting with a  
dot,  
unless you specify the File::FNM\_DOTMATCH argument. The reason is that  
files  
starting with a dot are hidden files and so you (usually) don’t want to  
take  
them into account.

However, I just discovered that it also returns false for file names  
starting  
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  
to  
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  
file,  
regardless of their extension, will be matched by fnmatch. This is not  
what  
most people expects. To make the above work, I’d either have to pass the  
flag  
File::FNM\_DOTMATCH to the fnmatch (which would have the unwanted side  
effect  
of also matching hidden files) or to manually remove the leading dot  
from the  
file name.

What do others think?

Stefano
