How to get list of directories in Lua

前端 未结 8 1913
离开以前
离开以前 2020-12-01 03:46

I need a list of directory in LUA

Suppose I have a directory path as "C:\\Program Files"

I need a list of all the folders in that particular path and

8条回答
  •  误落风尘
    2020-12-01 04:05

    I don't like installing libraries either and am working on an embedded device with less memory power then a pc. I found out that using 'ls' command lead to an out of memory. So I created a function that uses 'find' to solve the problem.

    This way it was possible to keep memory usage steady and loop all the 30k files.

    function dirLookup(dir)
       local p = io.popen('find "'..dir..'" -type f')  --Open directory look for files, save data in p. By giving '-type f' as parameter, it returns all files.     
       for file in p:lines() do                         --Loop through all files
           print(file)       
       end
    end
    

提交回复
热议问题