[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

File.fnmatch and **

Thomas Sondergaard

4/1/2005 9:50:00 AM

Dir.glob('**/*') matches directories recursively, but
File.fnmatch('**/*', "a/b/c", File::FNM_PATHNAME) returns false. I
thought (from reading the docs at ruby-doc.org) that the patterns are
supposed to be the same.

Can I match directories recursively with File.fnmatch?

Thomas
5 Answers

nobu.nokada

4/1/2005 1:34:00 PM

0

Hi,

At Fri, 1 Apr 2005 18:54:44 +0900,
Thomas Sondergaard wrote in [ruby-talk:136264]:
> Dir.glob('**/*') matches directories recursively, but
> File.fnmatch('**/*', "a/b/c", File::FNM_PATHNAME) returns false. I
> thought (from reading the docs at ruby-doc.org) that the patterns are
> supposed to be the same.

$ ruby18 -v -e 'p File.fnmatch("**/*", "a/b/c")'
ruby 1.8.2 (2005-03-31) [i686-linux]
true

--
Nobu Nakada


Thomas Sondergaard

4/3/2005 10:14:00 AM

0

nobu.nokada@softhome.net wrote:
> Hi,
>
> At Fri, 1 Apr 2005 18:54:44 +0900,
> Thomas Sondergaard wrote in [ruby-talk:136264]:
>
>>Dir.glob('**/*') matches directories recursively, but
>>File.fnmatch('**/*', "a/b/c", File::FNM_PATHNAME) returns false. I
>>thought (from reading the docs at ruby-doc.org) that the patterns are
>>supposed to be the same.
>
>
> $ ruby18 -v -e 'p File.fnmatch("**/*", "a/b/c")'
> ruby 1.8.2 (2005-03-31) [i686-linux]
> true
>

Yes, well the following returns true as well, which is not desirable. I
need to pass the File::FNM_PATHNAME for fnmatch to treat the string as a
path and not a file name.

[ts@argon qtruby-1.0.8]$ ruby -v -e 'p File.fnmatch("*", "a/b/c")'
ruby 1.8.2 (2004-12-25) [i686-linux]
true

I just wonder why only Dir.glob understands the ** pattern.

Thomas

Yukihiro Matsumoto

4/3/2005 2:50:00 PM

0

Hi,

In message "Re: File.fnmatch and **"
on Sun, 3 Apr 2005 19:14:42 +0900, Thomas Sondergaard <ts_news1@sondergaard.cc> writes:

|I just wonder why only Dir.glob understands the ** pattern.

(a) fnmatch conforms POSIX standard which does not contain **
pattern.

(b) besides that, there's no good implementation of fnmatch that
supports ** pattern when FNM_PATHNAME is specified.

matz.


H.Yamamoto

4/3/2005 3:20:00 PM

0

Hi.

Thomas Sondergaard <ts_news1@sondergaard.cc> wrote:
(2005/04/01 18:54)

>Dir.glob('**/*') matches directories recursively, but
>File.fnmatch('**/*', "a/b/c", File::FNM_PATHNAME) returns false. I
>thought (from reading the docs at ruby-doc.org) that the patterns are
>supposed to be the same.
>
>Can I match directories recursively with File.fnmatch?

Well, File.fnmatch on ruby1.9 works like that.

irb(main):002:0> File.fnmatch('**/*', 'a/b/c', File::FNM_PATHNAME)
=> true
irb(main):003:0> File.fnmatch('a**/*', 'a/b/c', File::FNM_PATHNAME)
=> false
irb(main):004:0> File.fnmatch('**/b*', 'a/b/c', File::FNM_PATHNAME)
=> false
irb(main):005:0> File.fnmatch('**/*', '/a/b/c', File::FNM_PATHNAME)
=> true
irb(main):006:0> File.fnmatch('**/*', 'c:/a/b/c', File::FNM_PATHNAME)
=> true

Does this fit your need?



Thomas Sondergaard

4/4/2005 6:55:00 AM

0

H.Yamamoto wrote:
> Well, File.fnmatch on ruby1.9 works like that.
>
> irb(main):002:0> File.fnmatch('**/*', 'a/b/c', File::FNM_PATHNAME)
> => true
> irb(main):003:0> File.fnmatch('a**/*', 'a/b/c', File::FNM_PATHNAME)
> => false
> irb(main):004:0> File.fnmatch('**/b*', 'a/b/c', File::FNM_PATHNAME)
> => false
> irb(main):005:0> File.fnmatch('**/*', '/a/b/c', File::FNM_PATHNAME)
> => true
> irb(main):006:0> File.fnmatch('**/*', 'c:/a/b/c', File::FNM_PATHNAME)
> => true
>
> Does this fit your need?
>

Yes, that's perfect!

Thanks,

Thomas