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.
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.
Might this do?:
Dir[“#{RAILS_ROOT}/public/folder/*”]
Dir.[] (and Dir.glob) are much like a unix shell glob in that it will
omit dotfiles unless the glob starts with a dot.