Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2015 00:09
Show Gist options
  • Save anonymous/15c49eaf3d913865500b to your computer and use it in GitHub Desktop.
Save anonymous/15c49eaf3d913865500b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Recursive Conditional Finder
def recursive_find(path, &condition)
# Create entry
entries = Array.new
# Look through all the files under specified directory
Dir[path + '/*'].each do |entry|
# If we find a directory, traverse it and append the files that meet the condition
entries << recursive_find(entry, condition) if File.directory? entry
# If we find a file, check it against the condition before appending it
entries << entry if condition.call entry
end
# Return the flattened list
entries.flatten
end
puts recursive_find ARGV[0] { |entry| File.extname(entry) == ".rb" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment