[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

possible DIR["**"] anomaly

Mike Durham

7/15/2006 1:52:00 AM

Hi,
If you see DEFINITION of DIR["**"] and DIR["*"] below it suggests there
should be some difference.
But if I run the CODE below I find they produce exactly the same output.
Is my documentation wrong or what am I doing wrong?
What would you think '** Matches subdirectories recursively' means?

Cheers, Mike


####
CODE
####
list = Dir["**"]
list.sort!
puts(list)

list = Dir["*"]
list.sort!
puts(list)

##########
DEFINITION
##########
Dir[ aString ] -> anArray
Returns anArray of filenames found by expanding the pattern given in
aString. Note that this pattern is not a regexp (it's closer to a shell
glob) and may contain the following metacharacters:

** Matches subdirectories recursively
* Matches zero or more characters
? Matches any single character
[ charSet ] Matches any character from the given set of characters. A
range of characters is written as charFrom-charTo. The set may be
negated with an initial uparrow (^).
{ opt, opt, ... } Matches any one of the optional strings
11 Answers

Trans

7/15/2006 3:10:00 AM

0


Mike Durham wrote:
> Hi,
> If you see DEFINITION of DIR["**"] and DIR["*"] below it suggests there
> should be some difference.
> But if I run the CODE below I find they produce exactly the same output.
> Is my documentation wrong or what am I doing wrong?
> What would you think '** Matches subdirectories recursively' means?
>
> Cheers, Mike
>
>
> ####
> CODE
> ####
> list = Dir["**"]
> list.sort!
> puts(list)
>
> list = Dir["*"]
> list.sort!
> puts(list)
>
> ##########
> DEFINITION
> ##########
> Dir[ aString ] -> anArray
> Returns anArray of filenames found by expanding the pattern given in
> aString. Note that this pattern is not a regexp (it's closer to a shell
> glob) and may contain the following metacharacters:
>
> ** Matches subdirectories recursively
> * Matches zero or more characters
> ? Matches any single character
> [ charSet ] Matches any character from the given set of characters. A
> range of characters is written as charFrom-charTo. The set may be
> negated with an initial uparrow (^).
> { opt, opt, ... } Matches any one of the optional strings

Try Dir['**/*'], it only applies this way.

T.


Mike Durham

7/15/2006 3:24:00 AM

0

transfire@gmail.com wrote:
> Mike Durham wrote:
>> Hi,
>> If you see DEFINITION of DIR["**"] and DIR["*"] below it suggests there
>> should be some difference.
>> But if I run the CODE below I find they produce exactly the same output.
>> Is my documentation wrong or what am I doing wrong?
>> What would you think '** Matches subdirectories recursively' means?
>>
>> Cheers, Mike
>>
>>
>> ####
>> CODE
>> ####
>> list = Dir["**"]
>> list.sort!
>> puts(list)
>>
>> list = Dir["*"]
>> list.sort!
>> puts(list)
>>
>> ##########
>> DEFINITION
>> ##########
>> Dir[ aString ] -> anArray
>> Returns anArray of filenames found by expanding the pattern given in
>> aString. Note that this pattern is not a regexp (it's closer to a shell
>> glob) and may contain the following metacharacters:
>>
>> ** Matches subdirectories recursively
>> * Matches zero or more characters
>> ? Matches any single character
>> [ charSet ] Matches any character from the given set of characters. A
>> range of characters is written as charFrom-charTo. The set may be
>> negated with an initial uparrow (^).
>> { opt, opt, ... } Matches any one of the optional strings
>
> Try Dir['**/*'], it only applies this way.
>
> T.
>
>

Thanks a lot.

Ara.T.Howard

7/15/2006 6:30:00 AM

0

Stefan Lang

7/15/2006 10:27:00 PM

0

On Saturday 15 July 2006 08:29, ara.t.howard@noaa.gov wrote:
> On Sat, 15 Jul 2006 transfire@gmail.com wrote:
> > Try Dir['**/*'], it only applies this way.
>
> i've settled on
>
> Dir['**/**']
>
> myself. anyone know the details on this poorly doccumented
> subject?

I use Dir['**/*'].

Generally I use a pattern of the form "<dir>/**/<pattern>"
to tell Ruby: "Give me all file names under <dir> and all
its subdirectories (recursively) that match <pattern>."

--
Stefan

Mike Durham

7/15/2006 11:58:00 PM

0

transfire@gmail.com wrote:
> Mike Durham wrote:
>> Hi,
>> If you see DEFINITION of DIR["**"] and DIR["*"] below it suggests there
>> should be some difference.
>> But if I run the CODE below I find they produce exactly the same output.
>> Is my documentation wrong or what am I doing wrong?
>> What would you think '** Matches subdirectories recursively' means?
>>
>> Cheers, Mike
>>
>>
>> ####
>> CODE
>> ####
>> list = Dir["**"]
>> list.sort!
>> puts(list)
>>
>> list = Dir["*"]
>> list.sort!
>> puts(list)
>>
>> ##########
>> DEFINITION
>> ##########
>> Dir[ aString ] -> anArray
>> Returns anArray of filenames found by expanding the pattern given in
>> aString. Note that this pattern is not a regexp (it's closer to a shell
>> glob) and may contain the following metacharacters:
>>
>> ** Matches subdirectories recursively
>> * Matches zero or more characters
>> ? Matches any single character
>> [ charSet ] Matches any character from the given set of characters. A
>> range of characters is written as charFrom-charTo. The set may be
>> negated with an initial uparrow (^).
>> { opt, opt, ... } Matches any one of the optional strings
>
> Try Dir['**/*'], it only applies this way.
>
> T.
>
>
using "**/*" doesn't seem to get all dirs, it misses the hidden ones
do you know the logic behind "**/*" or "*/*" ?
Cheers Mike


Pierre Barbier de Reuille

7/16/2006 9:21:00 AM

0

Mike Durham wrote:
> transfire@gmail.com wrote:
>> Mike Durham wrote:
>>> Hi,
>>> If you see DEFINITION of DIR["**"] and DIR["*"] below it suggests there
>>> should be some difference.
>>> But if I run the CODE below I find they produce exactly the same
>>> output.
>>> Is my documentation wrong or what am I doing wrong?
>>> What would you think '** Matches subdirectories recursively' means?
>>>
>>> Cheers, Mike
>>>
>>>
>>> ####
>>> CODE
>>> ####
>>> list = Dir["**"]
>>> list.sort!
>>> puts(list)
>>>
>>> list = Dir["*"]
>>> list.sort!
>>> puts(list)
>>>
>>> ##########
>>> DEFINITION
>>> ##########
>>> Dir[ aString ] -> anArray
>>> Returns anArray of filenames found by expanding the pattern
>>> given in
>>> aString. Note that this pattern is not a regexp (it's closer to a
>>> shell
>>> glob) and may contain the following metacharacters:
>>>
>>> ** Matches subdirectories recursively
>>> * Matches zero or more characters
>>> ? Matches any single character
>>> [ charSet ] Matches any character from the given set of
>>> characters. A
>>> range of characters is written as charFrom-charTo. The set may be
>>> negated with an initial uparrow (^).
>>> { opt, opt, ... } Matches any one of the optional strings
>>
>> Try Dir['**/*'], it only applies this way.
>>
>> T.
>>
>>
> using "**/*" doesn't seem to get all dirs, it misses the hidden ones
> do you know the logic behind "**/*" or "*/*" ?
> Cheers Mike
The convention in file globbing is always to ignore the hidden files,
unless explicitly stated otherwise.
Also, the documentation explicitly says that "**" match recursively the
/directories/, when "*" match any /files/.
But looking at the documentation, and mainly this bit:

librbfiles = File.join("**", "lib", "**", "*.rb")
Dir.glob(libdirs)

Make me wonder if anybody had proposed to use the operator / for joining
files component.
A recent addition to Python is a class that inherit string but with all
the facilities for paths (i.e. globbing, listing, joining, ...) and I
must say it is very convenient. The previous two lines could be written
something like:

librbfiles = Path.new("**")/"lib"/"**"/"*.rb"
librbfiles.glob

I think I will write it and post it here so that you may have a feeling
for what it can (or cannot) do.

Pierre


Nobuyoshi Nakada

7/16/2006 9:52:00 AM

0

Hi,

At Sun, 16 Jul 2006 18:20:31 +0900,
Pierre Barbier de Reuille wrote in [ruby-talk:202214]:
> librbfiles = File.join("**", "lib", "**", "*.rb")
> Dir.glob(libdirs)

You can do this on all platforms:

Dir.glob("**/lib/**/*.rb")

--
Nobu Nakada

Alex Young

7/16/2006 9:53:00 AM

0

Pierre Barbier de Reuille wrote:
<snip>
> Make me wonder if anybody had proposed to use the operator / for joining
> files component.
> A recent addition to Python is a class that inherit string but with all
> the facilities for paths (i.e. globbing, listing, joining, ...) and I
> must say it is very convenient. The previous two lines could be written
> something like:
>
> librbfiles = Path.new("**")/"lib"/"**"/"*.rb"
> librbfiles.glob
>
> I think I will write it and post it here so that you may have a feeling
> for what it can (or cannot) do.

Like this?

http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/classes/Pat...

--
Alex

Stefan Lang

7/16/2006 11:29:00 AM

0

On Sunday 16 July 2006 02:00, Mike Durham wrote:
> transfire@gmail.com wrote:
[...]
> > Try Dir['**/*'], it only applies this way.
> >
> > T.
>
> using "**/*" doesn't seem to get all dirs, it misses the hidden
> ones do you know the logic behind "**/*" or "*/*" ?

Use:
Dir.glob("**/*", File::FNM_DOTMATCH)

Dir[patttern] is just a shortcut for Dir.glob(pattern, 0).
Just read "ri Dir.[]" and "ri Dir.glob".

HTH,
Stefan


Pierre Barbier de Reuille

7/16/2006 1:24:00 PM

0

Alex Young wrote:
> Pierre Barbier de Reuille wrote:
> <snip>
>> Make me wonder if anybody had proposed to use the operator / for joining
>> files component.
>> A recent addition to Python is a class that inherit string but with all
>> the facilities for paths (i.e. globbing, listing, joining, ...) and I
>> must say it is very convenient. The previous two lines could be written
>> something like:
>>
>> librbfiles = Path.new("**")/"lib"/"**"/"*.rb"
>> librbfiles.glob
>>
>> I think I will write it and post it here so that you may have a feeling
>> for what it can (or cannot) do.
>
> Like this?
>
> http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/classes/Pat...
>
Indeed ^^
I didn't yet know half the ruby classes :/
The only thing is, instead of +, IMHO the operator / would make more
sense for joining paths.

But ok, it is already existing :)

Pierre