面臨跌破發行eventhough該文件存在的文件夾中。沒有這樣的文件或目錄@ rb_sysopen紅寶石
H:\Ruby_test_works>ruby hurrah.rb
hurrah.rb:7:in `read': No such file or directory @ rb_sysopen - H:/Ruby_
test_works/SVNFolders.txt (Errno::ENOENT)
from hurrah.rb:7:in `block in <main>'
from hurrah.rb:4:in `each_line'
from hurrah.rb:4:in `<main>'
輸入文件(input.txt)列以製表符分隔。
10.3.2.021.asd 10.3.2.041.def SVNFolders.txt
SubversionNotify Subversionweelta post-commit.bat
Commit message still rake customemail.txt
mckechney.com yahoo.in ReadMe.txt
代碼:
dir = 'H:/Ruby_test_works'
file = File.open("#{dir}/input.txt", "r")
file.each_line do |line|
initial, final, file_name = line.split("\t")
#puts file_name
old_value = File.read("#{dir}/#{file_name}")
replace = old_value.gsub(/#{Regexp.escape(initial)}, #{Regexp.escape(final)}/)
File.open("#{dir}/#{file_name}", "w") { |fi| fi.puts replace }
end
我一直在使用向前和向後斜槓,但沒有運氣嘗試。我錯過了什麼,不確定。謝謝。
puts file_name
給出了下面的值
SVNFolders.txt
post-commit.bat
customemail.txt
ReadMe.txt
在輸入文件中,提到的文件名有空格,就像'SVN Folders.txt'一樣,但是在錯誤中,同樣的文件會這樣讀'SVNFolders.txt 」。你的文件名是否有空格? – Ucpuzz
讓我得到這個直...只有一個** **文件中'H:/ Ruby_test_works':'input.txt'。該文件包含四行文本,每行都以另一個文件名結尾。然後嘗試打開該文件...但文件**不存在**。這是你的錯誤信息。沒有'H:/ Ruby_test_works/SVNFolders.txt'這樣的文件。那麼你的問題到底是什麼? –
@Ucpuzz:對不起,這是一個複製粘貼問題。文件沒有名字空間 – Goku