Last active
August 29, 2015 14:25
-
-
Save kirillzh/5eafd4baac615961a0cc to your computer and use it in GitHub Desktop.
Array of absolute file paths
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
# 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