4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/reprefix.rb', line 4
def self.rename(old_prefix, new_prefix)
puts "⌛⌛⌛ 修改前缀中..."
pattern = Regexp.new(old_prefix)
Find.find(Dir.pwd).each do |file_path|
if !File.directory?(file_path) && File.extname(file_path) != '.rb'
text = File.read(file_path).encode!('UTF-8', 'UTF-8', :invalid => :replace) replace = text.gsub(pattern, new_prefix) File.open(file_path, "w") do |file| file.puts replace
end
file_dir = File.dirname(file_path) file_name = File.basename(file_path) new_file_name = file_name.gsub(pattern, new_prefix); new_file_path = File.join(file_dir, new_file_name)
File.rename(file_path, new_file_path)
end
end
puts "✅✅✅ 修改前缀完成"
end
|