Advertisement
Zac_McDonald

Everything into one big text file

Jun 8th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.87 KB | None | 0 0
  1. # Will read files and output into one big file with filename headers
  2.  
  3. def one_big_file (search_root)
  4.     files = Dir[search_root + '/**/*']
  5.     file_types = [".rb"]
  6.  
  7.     output_text = ""
  8.  
  9.     # Read File contents
  10.     for i in 0...file_types.length
  11.         file_type = files.select { |f|
  12.             f.end_with?(file_types[i])
  13.         }
  14.  
  15.         file_type.each { |f|
  16.             file_text = File.read(Dir.pwd + "/" + f)
  17.             output_text += ("=" * 80) + "\n" + f + "\n" + ("=" * 80) + "\n\n" + file_text + "\n\n"
  18.         }
  19.     end
  20.  
  21.     # Output to File
  22.     output_file = File.open("./one_big_file.txt", "w")
  23.     output_file.puts output_text
  24.     output_file.close
  25. end
  26.  
  27. search_root = ARGV[0]
  28.  
  29. if (search_root != nil)
  30.     one_big_file(search_root)
  31. else
  32.     puts "Please have a search root as an argument.\nUse: \"FOLDER_NAME\" - with quotation marks\nDo not use \"./\" to begin path.\ni.e. ruby one_big_file.rb \"Tower Defence Game\""
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement