Skip to content

Instantly share code, notes, and snippets.

@thebatu
Last active July 9, 2023 00:10
Show Gist options
  • Save thebatu/e4a03ec96090e0cde92e33fcd45044a2 to your computer and use it in GitHub Desktop.
Save thebatu/e4a03ec96090e0cde92e33fcd45044a2 to your computer and use it in GitHub Desktop.
Ruby script to read an Android project and transform it into a single txt file to feed it to chatGPT
require 'find'
def read_directory(dir_path, output_file_path)
File.open(output_file_path, 'w') do |output_file|
Find.find(dir_path) do |path|
if FileTest.directory?(path)
if File.basename(path) == 'build'
Find.prune # Don't look any further into this directory.
else
next
end
else
# Skip the "google-services.json" file
next if File.basename(path) == 'google-services.json'
if path.end_with?(".java") || path.end_with?(".kt")
read_file(path, output_file)
end
end
end
end
end
def read_file(file_path, output_file)
File.open(file_path, "r") do |file|
output_file.write("----- Reading file: #{file_path} -----\n")
file.each_line do |line|
output_file.write(line)
end
output_file.write("\n")
end
end
# Your project path
project_path = '/Users/bats/AndroidStudioProjects/ZiadArtwork'
# Your output file path
output_file_path = '/Users/bats/AndroidStudioProjects/ZiadArtwork/code_output.txt'
read_directory(project_path, output_file_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment