global
def find_files(pattern, paths = ['', Dir.pwd], exclude_dirs: false)
find_files('version.rb', ['lib/**', 'spec'], true)
Example:
excluding directories if exclude_dirs is true.
Array
Returns:
exclude_dirs (Boolean): If true, excludes "." and ".." and directory names from the results.
Paths can include wildcards for recursive search.
paths (Array
pattern (String): A filename or a pattern string with wildcards.
Args:
path specification (e.g., 'dir/**' for recursive search).
are included in the search. The search can include subdirectories depending on the
It searches for files matching the pattern within each of the specified paths. Hidden files
option to exclude directory entries and special entries "." and "..".
The function takes a pattern (filename or pattern with wildcards), an array of paths, and an
"." and ".." entries and directory names from the results.
Finds files matching a given pattern within specified directory paths while optionally excluding
def find_files(pattern, paths = ['', Dir.pwd], exclude_dirs: false) matched_files = [] paths.each do |path_with_wildcard| # Combine the path with the wildcard and the pattern search_pattern = File.join(path_with_wildcard, pattern) # Use Dir.glob with the File::FNM_DOTMATCH flag to include hidden files files = Dir.glob(search_pattern, File::FNM_DOTMATCH) # Optionally exclude "." and ".." and directory names if exclude_dirs files.reject! { |file| file.end_with?('/.', '/..') || File.directory?(file) } end matched_files += files end matched_files.uniq end