Robert Klemme
10/5/2007 7:21:00 AM
2007/10/5, Leon Bogaert <leon@tim-online.nl>:
> This would work:
>
> i = 0; dir = "/home/leon/"; test = Array.new; test =
> Dir.new(dir).entries.map! { |x| x =~ /filezilla$/ ? x : next };
> test.compact
>
> Is the .compact needed? Can't I get rid of that?
You need it with your code because the map! will map some values to
nil. You probably rather want #select.
files = Dir.new(dir).entries.select { |x| /filezilla$/ =~ x }
But you can have that much easier with
files = Dir["/home/leon/*filezilla"]
Kind regards
robert