I'm trying to get the Dir.glob of an absolute path:
path = "/Users/ken/templates" scaffold = Dir.glob("#{path}/*.erb", File::FNM_DOTMATCH) p scaffold.inspect This is my directory structure:
/Users/ken/templates/test.erb /Users/ken/templates/test2.erb /Users/ken/templates/app/one.erb /Users/ken/templates/app/two.erb When I run on the directory I only get the files in the root of the directory:
"[\"/Users/ken/farmstead/test.erb\", \"/Users/ken/farmstead/test2.erb\"]" But no entries for the app subdirectory.
How do I get the Glob to go recursive on the absolute path?
2 Answers
To get into subdirectories, one needs to instruct Dir#glob to get into subdirectories:
# ⇓⇓⇓ scaffold = Dir.glob("#{path}/**/*.erb", File::FNM_DOTMATCH) Quote from the documentation I linked:
2**
Matches directories recursively.
A cleaner way to tell glob about the absolute directory is to use the base parameter like so:
Dir.glob("**/*.erb", base: path)