【发布时间】:2021-10-13 11:25:26
【问题描述】:
我将文件名保存为 lua 中的文本文件,然后想在 texfile 中搜索文件名。我的问题是我只是得到了搜索到的字符串,而不是整个文件名。
这是我的代码:
local file,err = io.open("C:\\Users\\lamu7789\\Documents\\Lua_Plugins\\test_file_reader \\channels.txt", 'w')
if file then
for dir in io.popen([[dir "C:\Users\lamu7789\Documents\Lua_Plugins\test_file_reader\textfiles" /b]]):lines() do
file:write(dir.."\n")
end
file:close()
else
print("error: ", err)
end
channel = "0x"..string.upper("10")
local file = io.open("C:\\Users\\lamu7789\\Documents\\Lua_Plugins\\test_file_reader\\channels.txt", "rb")
if not file then return nil end
local String = file:read "*a"
local name = String:match(channel)
print(name)
file:close()
对于这个例子,我得到“0x10”。 这就是路径的样子和“print(String)”打印出来的样子:
我想要返回的是这样的:“0x10_adress_second.txt”。 这里有什么问题? 感谢您的帮助。
【问题讨论】: