Sha256: 69959714fa574b99bb2859a3b1ca254dfb8c3f1e5ac5c89a3252a3af08e39568
Contents?: true
Size: 831 Bytes
Versions: 1
Compression:
Stored size: 831 Bytes
Contents
require 'find' def prepend_to_files_in_folder path, filetype, string_to_append filetype_regex = /.*#{filetype}/ total_file_count = 0 Find.find(path) do |directories_and_files| if File.file?(directories_and_files) and filetype_regex =~ directories_and_files begin File.open(directories_and_files, 'r') do |old_file| temp_string_array = old_file.readlines.join end File.open(directories_and_files, 'w') do |new_file| new_file << string_to_append new_file << temp_string_array end rescue => error puts "I errored with this error: #{error}" end puts "#{directories_and_files}" total_file_count += 1 end end if total_file_count == 0 puts "No matched file(s) was(were) found." else puts "#{total_file_count} file(s) was(were) updated." end endP
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
FilePrepender-0.0.0.0.1 | lib/FilePrepender.rb |