Can't imagine this is right (Linux, Ruby 1.8.4)
Dir.glob('lib/**/*') #=> [ 'lib/facets.rb' ]
File.fnmatch?('lib/**/*', 'lib/facets.rb') #=> false
In the mean time, anyone got a working Ruby-coded #fnmatch? I can use?
T.
Can't imagine this is right (Linux, Ruby 1.8.4)
Dir.glob('lib/**/*') #=> [ 'lib/facets.rb' ]
File.fnmatch?('lib/**/*', 'lib/facets.rb') #=> false
In the mean time, anyone got a working Ruby-coded #fnmatch? I can use?
T.
Hi!
It does seem strange...
JRuby does it like this in Java, it should be exceedingly trivial to
convert to Ruby:
checkArgumentCount(args, 2, -1);
String pattern = args[0].convertToString().toString();
RubyString path = args[1].convertToString();
int opts = (int) (args.length > 2 ?
args[2].convertToInteger().getLongValue() : 0);
boolean dot = pattern.startsWith(".");
pattern = pattern.replaceAll("(\\.)", "\\\\$1");
pattern = pattern.replaceAll("(?<=[^\\\\])\\*", ".*");
pattern = pattern.replaceAll("^\\*", ".*");
pattern = pattern.replaceAll("(?<=[^\\\\])\\?", ".");
pattern = pattern.replaceAll("^\\?", ".");
if ((opts & FNM_NOESCAPE) != FNM_NOESCAPE) {
pattern = pattern.replaceAll("\\\\([^\\\\*\\\\?])", "$1");
}
pattern = pattern.replaceAll("\\{", "\\\\{");
pattern = pattern.replaceAll("\\}", "\\\\}");
pattern = "^" + pattern + "$";
if (path.toString().startsWith(".") && !dot) {
return getRuntime().newBoolean(false);
}
return getRuntime().newBoolean(Pattern.matches(pattern,
path.toString()));
Regards
Ola Bini
----- Original Message -----
From: transfire@gmail.com
Date: Thursday, June 8, 2006 2:02 pm
Subject: glob but not fnmatch?
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Can't imagine this is right (Linux, Ruby 1.8.4)
Dir.glob('lib/**/*') #=> [ 'lib/facets.rb' ]
File.fnmatch?('lib/**/*', 'lib/facets.rb') #=> false
In the mean time, anyone got a working Ruby-coded #fnmatch? I can use?
T.
As far as I can see File.fnmatch does not support directory path
matching with "**":
http://www.ruby-doc.org/core/classes/File.html#M000012
So although this may seem inconvenient / asymmetric behavior conforms
at least to the docs.
robert
2006/6/8, transfire@gmail.com <transfire@gmail.com>:
Can't imagine this is right (Linux, Ruby 1.8.4)
Dir.glob('lib/**/*') #=> [ 'lib/facets.rb' ]
File.fnmatch?('lib/**/*', 'lib/facets.rb') #=> false
In the mean time, anyone got a working Ruby-coded #fnmatch? I can use?
--
Have a look: Robert K. | Flickr