我想将一个表写入一个文件,该文件以其创建的日期和时间命名。 我可以打开硬编码名称的文件,写入表格进去,象下面这样:如何用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