Here are two ways to use glob
to recursively list directories:
Dir.glob("**/*/")
Dir.glob("**/")
The output appears to be the same, at least for a small subtree. Is there a difference between those two commands I am missing out on?
The ** matches 0 or more directories. By placing a * at the end you remove directories in the root, essentially making it 1 or more:
a = Dir.glob('/tmp/**/*/').sort
b = Dir.glob('/tmp/**/').sort.size
b.size => 19
a.size => 18
b - a => ["/tmp/"]
Without a leading constant path though, it doesn't look like there is a difference as 0 length matches aren't interesting and don't get put in the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With