-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplaceString.rb
More file actions
34 lines (29 loc) · 946 Bytes
/
ReplaceString.rb
File metadata and controls
34 lines (29 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def ReplaceString(directory, target, replace)
files = []
Dir.foreach(directory) do |file| files << file end
#files.each do |file| puts file end
#
files.each do |file|
filePath = directory + "\\" + file
if file == "." or file == ".." or File.directory?(filePath) or File.extname(filePath) != ".sql"
else
print file
if !File.readable?(filePath) then
puts " cannot be read."
next
end
if !File.writable?(filePath) then
puts " cannot be written."
next
end
object = File.open(filePath, "r")
text = object.read
object.close
text.gsub!(target, replace)
#puts text
File.open(filePath, "w") {|content| content << text}
puts " replaced."
end
end
end
ReplaceString(ARGV[0], ARGV[1], ARGV[2])