Skip to content

Instantly share code, notes, and snippets.

@kirillzh
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirillzh/5eafd4baac615961a0cc to your computer and use it in GitHub Desktop.
Save kirillzh/5eafd4baac615961a0cc to your computer and use it in GitHub Desktop.
Array of absolute file paths
# Recursively get absolute paths of the files with specified extension in specified directory
#
# @param ext [String] extension of the files to look for (default - any extension)
# @param pwd [String] absolute or relative path where to look for the files (default - current directory)
# @param list [Array<String>] used to recursively store absolute paths (default - [])
# @return [Array<String>] Array array of absolute paths of files in the directory with specified extension
def files(ext = '.*', pwd = Dir.pwd, list = [])
Dir[File.expand_path(File.join(pwd, '*'))].each do |path|
if File.directory?(path)
files(ext, path, list)
else
list << path if File.extname(path) =~ Regexp.new(ext, true)
end
end
list
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment