file - Lua 读取文件并写入新文件
问题描述
我需要复制一个文件并将扩展名从 .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
,达到预期的效果。
推荐阅读
- verilog - 对条件语句使用向量位选择
- excel - 从单元格 i 循环到最后一个单元格非空单元格
- java - Gradle:如何使静态资源在同一项目模块的类路径上可用
- python - 如何有效地在python中循环opencv代码
- java - Java中是否有与Promise.race()等价的东西?
- docker - docker如何在同一主机上的默认桥上处理不同容器之间的通信?
- php - 如何解决在数组错误时调用成员函数 only()
- javascript - 迭代 zip 可迭代以在表中生成多行 - Reactjs
- python - waitForObject 返回匹配模式的第一个对象。有没有办法获得所有对象的列表?
- css - 当 Flexbox 组件包装时向下推 Grid Container