[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Finding files in a directory and regexp

Hal E. Fulton

7/25/2006 6:03:00 AM

Alexander Lamb wrote:
> Hello,
>
> I am doing something like this:
>
> Find.find("/Users/alamb/_Current-Work/fiches") do |path|
> if(path =~ /100_/)
> ...
>
> In order to get all the files of the directory which have "100_" in the
> name.
>
> Two questions:
>
> 1) Is there a way to use the find method to directly achieve this?
> 2) I tried a Regexp with /^100_/ to say "files starting with '100_' "
> but it doensn't seem to work.

I don't usually use Find... Dir is fairly powerful.

Dir["100*"] # all 100-type files in current dir
Dir["**/100*"] # all in this tree (correct syntax??)


Hal


1 Answer

rio4ruby

7/27/2006 5:47:00 AM

0

One could use Rio (rio.rubyforge.org)

This would find the files which start with '100_'

rio("/Users/alamb/_Current-Work/fiches").files(/^100_/) do |path|
...
end

To include files in subdirectories that start with '100_' use:

rio("/Users/alamb/_Current-Work/fiches").all.files(/^100_/) do |path|
...
end


Hal Fulton wrote:
> Alexander Lamb wrote:
> > Hello,
> >
> > I am doing something like this:
> >
> > Find.find("/Users/alamb/_Current-Work/fiches") do |path|
> > if(path =~ /100_/)
> > ...
> >
> > In order to get all the files of the directory which have "100_" in the
> > name.
> >
> > Two questions:
> >
> > 1) Is there a way to use the find method to directly achieve this?
> > 2) I tried a Regexp with /^100_/ to say "files starting with '100_' "
> > but it doensn't seem to work.
>
> I don't usually use Find... Dir is fairly powerful.
>
> Dir["100*"] # all 100-type files in current dir
> Dir["**/100*"] # all in this tree (correct syntax??)
>
>
> Hal