The thing with glob is that it can match subpaths. When you write Dir.glob('*/*')
it'll return all the files and directories directly under subdirectories of the current directories. It can do that because glob patterns are simple enough for the computer to understand - if it was regex it would have to scan the entire filesystem and compare each path with the pattern, which is simply too much.
However, you can combine - use Dir.glob
to choose where to search, and grep
to choose what to search:
[1] pry(main)> Dir.glob('/usr/lib/*').grep(/\/lib[A-Z]+\.so$/)
=> ["/usr/lib/libFLAC.so", "/usr/lib/libEGL.so", "/usr/lib/libHACD.so", "/usr/lib/libLTO.so", "/usr/lib/libGLEW.so", "/usr/lib/libGL.so", "/usr/lib/libSDL.so", "/usr/lib/libGLU.so", "/usr/lib/libSM.so", "/usr/lib/libICE.so"]
Find
to walk directories and do a regex against them [?] https://mcmap.net/q/491840/-what-39-s-the-ruby-equivalent-of-python-39-s-os-walk – Paleozoologyls
at the command-line. – Antineutrinoselect
andreject
to find matches, or within blocks usingnext
orprune
. – Antineutrino