-
-
Save anonymous/15c49eaf3d913865500b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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