Lua读取文件并写入新文件

问题描述 投票:0回答:1

我需要复制文件并将扩展名从.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)

file lua
1个回答
0
投票

您可以在打开要写入的文件之前修改source_filenamesource_filename = source_filename:gsub("seq$", "mid")。这会将文件名末尾的seq替换为mid,以达到所需的效果。

© www.soinside.com 2019 - 2024. All rights reserved.