你能告訴我爲什麼這段代碼給出錯誤嗎?從另一個文本文件的一行創建一個新文件(名稱)
我不理解這行:File.new("#{line}", "w")
system "ipconfig /all > info.txt"
info_text = File.open("info.txt")
info_text.each { |line|
if line =~ /Physical Address/
line.slice! " Physical Address. . . . . . . . . : "
File.new("#{line}", "w")
end
}
感謝-MikeW¯¯
注:您的'使用File.new'保持文件句柄開放,直到腳本退出。雖然短命的腳本並不是什麼大不了的。 – Kelvin