编辑批次&的权限被拒绝使用ruby脚本的autoit(au3)文件

时间:2014-09-01 11:05:25

标签: ruby batch-processing autoit batch-rename

我的目录包含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>'

1 个答案:

答案 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