If you're comfortable only following one level of symlinks (e.g. not recursing into a symlink inside a symlink), you can do it all in one line:

```rb
Dir[prefix + '/**{,/*/**}/*'].uniq.select { |f| File.file?(f) }
```