我需要复制文件并将扩展名从.seq更改为mid(不使用shell命令)这个有效
file = io.open(source_filename, "rb")
source_content = file:read("*all")
file = io.open(source_filename ..".mid", "wb")
file:write(source_content)
file:close()
我得到Song.seq.mid
但我想Song seq.mid
如果我做一个
source_filename = string.gsub(source_filename, ".seq", ".mid")
file = io.open(source_filename, "wb")
然后文件的值为零file:write(source_content)
您可以在打开要写入的文件之前修改source_filename
:source_filename = source_filename:gsub("seq$", "mid")
。这会将文件名末尾的seq
替换为mid
,以达到所需的效果。