求 LUA 统计一个文件夹里面有.xlsx的文件个数

求 LUA 统计一个文件夹里面有.xlsx的文件个数,第1张

C:\Program Files (x86)\Lua\咐颤早5.1>lua.exe -lilua

ILUA: Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio

"quit" to end

>require("ex")

table: 005F8430

>洞迅 os.currentdir()

'C:\Program Files (x86)\Lua\5.1'

>衡雀 for e in assert(os.dir("c:/code")) do print(e.name) end

.sconsign.dblite

asn.patch

...

你可嫌李以参考如下实例代码:function getFile(file_name) 

    local f = assert(io.open(file_name, 'r'))

    local string = f:read("*all")

    f:close()

    return string

end function writeFile(file_name,string)

 local f = assert(io.open(file_name, 'w'))

 f:write(string)

 f:close()

end --从命令行获取参数, 如果有参数则遍历指定目录,没有参数遍历当前目录 if arg[1] ~= nil then

     cmd = "ls "..arg[1]

else

     cmd = "汪埋ls" end print("cmd", cmd)

--io.popen 返回的是一个FILE,跟c里面的popen一样 local s = io.popen(cmd)

local fileLists = s:read("*all")

print(fileLists)

while true do --从文件列表里一行一行的获取文件名 _,end_pos, line = string.find(fileLists, "([^\n\r]+.txt)", start_pos)

        if not end_pos then break end --    print ("wld", line) local str = getFile(line)

    --把每一行的末尾 1, 替换为 0, local new =string.gsub(str, "1,\n", "0,\n")

    --替换后的字符串写入到文件。以前的内容会清空     writeFile(line, new)

    start_pos 芹陵迟= end_pos + 1 end

Lua文件是基本,但是要整清冲合起来盯正册的话,需要1个目录凯宏哦。这个目录就是Toc文件。

如果Toc文件内只有1.lua 没有2.Lua 3.Lua在游戏封装的时候,是不会读取的。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/8155094.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存