我的目录包含bat&自动文件
我的红宝石剧本
Dir.foreach('C:/Users/Public/qa/Libs/Model') do |file|
puts file
aFile=File.open("C:/Users/Public/qa/Libs/Model/#{file}","r")
IO.foreach(aFile){|block| aFile.puts block.gsub(/Model_No/,"#{Model_No}")}
aFile.close
end
生成错误
C:/Users/Public/qa/Testcases/Default_test/temp.rb:23:in `initialize': Permission denied - C:/Users/Public/qa/Libs/Model/. (Errno::EACCES)
from C:/Users/Public/qa/Testcases/Default_test/temp.rb:23:in `open'
from C:/Users/Public/qa/Testcases/Default_test/temp.rb:23:in `block in <main>'
from C:/Users/Public/qa/Testcases/Default_test/temp.rb:20:in `foreach'
from C:/Users/Public/qa/Testcases/Default_test/temp.rb:20:in `<main>'
答案 0 :(得分:1)
错误是因为“。”和“..”
Dir.foreach('C:/Users/Public/qa/Libs/Model_No') do |fil|
if !File.directory?(fil)
puts fil
aFile=File.open("C:/Users/Public/qa/Libs/Model_No/#{fil}","r+")
IO.foreach(aFile){|block| aFile.puts block.gsub(/123/,"#{Model_No}")}
aFile.close
end
end