Say, I want to get all files in one folder. Since Dir.entries will
have “.” and “…” included. I want to strip them out with “grep”. I
tried to write in such a way as I can did similarly in Perl:
log_files = Dir.entries(log_dir).grep(!/^…?/)
But, it is a syntax error to have “!/regex/” as grep’s argument.
Should I use some trick to make grep accept “not-match” regex?
At Tue, 5 Jun 2007 18:55:02 +0900,
Morgan C. wrote in [ruby-talk:254395]:
Say, I want to get all files in one folder. Since Dir.entries will
have “.” and “…” included. I want to strip them out with “grep”. I
tried to write in such a way as I can did similarly in Perl:
log_files = Dir.entries(log_dir).grep(!/^…?/)
Say, I want to get all files in one folder. Since Dir.entries will
have “.” and “…” included. I want to strip them out with “grep”. I
tried to write in such a way as I can did similarly in Perl:
log_files = Dir.entries(log_dir).grep(!/^…?/)
But, it is a syntax error to have “!/regex/” as grep’s argument.
Should I use some trick to make grep accept “not-match” regex?
Use #reject:
Dir.entries(".").reject {|x| /\A.+\z/ =~ x}
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.