I want to glob a directory to post-process header files. Yet I want to exclude some directories in the project. Right now the default way is…
Dir["**/*.h"].each { |header|
puts header
}
Seems inefficient to check each header entry manually if it’s in an excluded directory.
Don’t use globbing, instead use
Find. Find is designed to give you access to the directories and files as they’re encountered, and you programmatically decide when to bail out of a directory and go to the next. See the example on the doc page.If you want to continue using globbing this will give you a starting place. You can put multiple tests in
rejector’d together:You can use either fixed-strings or regex in the tests.