Finding files in a directory and regexp

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.

Any idea?

Thanks

Alexander L.
Service d’Informatique Médicale
Hôpitaux Universitaires de Genève
[email protected]
+41 22 372 88 62
+41 79 420 79 73

Alexander L. wrote:

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs