Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > File.fnmatch? doesn't distinguish between .filename and ./filename ?

Thread Tools

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

Stefano Crocco
Posts: n/a
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?


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to distinguish between Events and States? Vinodh Kumar P C++ 1 12-12-2003 01:42 AM
distinguish between char* and char[x] mosfet C++ 6 11-27-2003 01:28 AM
How to distinguish between Olympus refurbished and new? Jerry Nash Digital Photography 4 11-19-2003 05:22 PM
Way to distinguish between POST and GET data in Python CGIs? Simon Willison Python 1 08-28-2003 09:32 AM
How to distinguish between stdout and stderr Andre C Programming 7 07-21-2003 01:57 PM