Skip to content

Instantly share code, notes, and snippets.

@fhyfirman
Created September 3, 2024 10:18
Show Gist options
  • Save fhyfirman/f83235afd495955540c39be985b10e41 to your computer and use it in GitHub Desktop.
Save fhyfirman/f83235afd495955540c39be985b10e41 to your computer and use it in GitHub Desktop.
Ruby Script for List All Matching Pattern Files
require 'find'
# Define the directory to search
directory_to_search = 'app/views'
# Define the pattern to match files
file_pattern = /.*_th\.html\.erb$/
# Define the output file
output_file = 'email_templates_th.txt'
# Initialize an array to hold the matching file paths
matching_files = []
# Search for files matching the pattern
Find.find(directory_to_search) do |path|
if path =~ file_pattern
matching_files << path
end
end
# Write the matching file paths to the output file
File.open(output_file, 'w') do |file|
matching_files.each { |file_path| file.puts(file_path) }
end
puts "Matching files have been listed in #{output_file}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment