Skip to content

Instantly share code, notes, and snippets.

@ebot
Last active December 19, 2015 02:49
Show Gist options
  • Select an option

  • Save ebot/5885568 to your computer and use it in GitHub Desktop.

Select an option

Save ebot/5885568 to your computer and use it in GitHub Desktop.
Oh Wilbur, we will call you Frank.
#!/usr/bin/env ruby -wKU
require 'fileutils'
def fix_frank(dir_name)
Dir.new(dir_name).each do |file_name|
file_path = File.join dir_name, file_name
index_path = File.join file_path, 'index.txt'
if file_name == 'data' and File.exist? index_path
puts " Checking for \"FRANK\" in #{index_path}"
franks = 0
input = File.new index_path, 'r'
tmp = File.new 'swap_index.txt', 'w'
input.each_line do |line|
unless line.include? '"FRANK"'
tmp << line
else
franks += 1
tmp << line.gsub( '"FRANK"', '""FRANK""' )
end
end
input.close
tmp.close
if franks != 0
puts " #{franks} \"FRANKS\" Found"
FileUtils.mv index_path, "#{index_path}.frank_backup"
FileUtils. mv 'swap_index.txt', "#{file_path}/index.txt"
else
puts ' No "FRANKS" Found'
end
elsif File.directory? file_path and file_name != '.' and file_name != '..'
puts "Reading #{file_name}"
fix_frank file_path
end
end
end
fix_frank '.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment