我想將一個表寫入一個文件,該文件以其創建的日期和時間命名。 我可以打開硬編碼名稱的文件,寫入表格進去,象下面這樣:如何用lua中的當前日期和時間創建文件名?
FILENAME_EVENTS="Events.txt" -- filename in string
local fp=io.open(FILENAME_EVENTS, a) -- open a new file with the file name
io.output(FILENAME_EVENTS) -- redirect the io output to the file
-- write the table into the file
for i, e in ipairs(eventlist) do io.write(e.title, e.category, e.ds, e.de, e.td) end
但是當我嘗試:
FILENAME_EVENTS=os.date().."\.txt" -- filename in string with date
local fp=io.open(FILENAME_EVENTS, a) -- open a new file with the file name
io.output(FILENAME_EVENTS) -- redirect the io output to the file
-- write the table into the file
for i, e in ipairs(eventlist) do io.write(e.title, e.category, e.ds, e.de, e.td) end
我得到一個錯誤 壞參數#1 'output'(10/06/11 17:45:01.txt:無效參數) 堆棧回溯: [C]:in function'output'
爲什麼這個「10/06/11 17:45: 01.txt「是一個無效的參數?由於它包含空格或'/'?或者其他原因?
BTW,該平臺是WIN7專業版+的Lua 5.1.4勝利
什麼平臺這是什麼?這不應該發生。 – cnicutar
Win7 Pro + lua5.1.4 for win – xdan