[Rails] Re: Regular expression and reading directories
by Jdswift other posts by this author
Jan 31 2007 8:39PM messages near this date
[Rails] Re: Regular expression and reading directories
|
[Rails] Re: Regular expression and reading directories
You could try:
directory = Dir.open("#{RAILS_ROOT}/public/folder")
@files_and_folders = directory.to_a.select {|i| /(^\..?$)|(.svn
$)/.match(i) }
On Feb 1, 12:42 pm, rph <rails-mailing-l...@[...].net> wrote:
> I have to read in a list of folders and display them to the user.
> However, there are certain folders that I don't want to show up, and I'm
> trying to restrict this using regular expressions, which I'm not so good
> at.
>
> There are things like "." and ".." and "_svn" that show up, that I'm
> trying to restrict.
>
> Here's my method (which isn't working):
>
> def view_directory
> @files_and_folders = []
> reg_exp = Regexp.new(/^$/) # what regexp goes in here?
> Dir.foreach("#{RAILS_ROOT}/public/folder") do |f|
> @files_and_folders << f if f != reg_exp
> end
> end
>
> This may not even be the best way to handle this, as I've never dealt
> with files/directories before. Any thoughts on the regular expression,
> or a better way? Thanks.
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Ta
lk" group.
To post to this group, send email to rubyonrails-talk@[...].com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@[...].com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thread:
Rph
George Ogata
Jdswift
Rph
Rph
|