Lua traversal folder

1. Traverse all lua files under the file, This can be changed, only use luaforwindow to execute

[plain] view plain copy

< /div>

  1. –dofile(“F:/Program_Files/Lua/lua_script/csvtolua/get_csv.lua”)
  2. require”lfs”
  3. functionfindindir(path,wefind,r_table,intofolder )
  4. for file in lfs.dir(path) do
  5. If file~=”.” and file~= “..” then
  6. local f = path.. ‘\\’..file
  7. –print(“/t”..f)
  8. if string.find(f, wefind) ~= nil then
  9. –print(“/t”..f)
  10. table.insert(r_table,f)
  11. end end
  12. local attr=lfs.attributes(f)
  13. ass ert(type(attr)==”table”)
  14. If attr.mode== “directory” and intofolder then
  15. findindir (f, wefind, r_table, intofolder)
  16. Else
  17. –for name, value in pairs(attr) do
  18. print (name, value)
  19. end end
  20. end
  21. end
  22. end
  23. local currentFolder=[[F:\Program_Files\Lua\lua_script\csvtolua]]
  24. —————— ——————-
  25. local input_table={}
  26. findindir(currentFolder, “%.lua”, input_table, false)–Find the lua file, you can change it here
  27. i=1
  28. while input_table[i]~=nil do
  29. print(input_table[i])
  30. i=i+1
  31. end


This is the result of execution:< /span>

1. Traverse all the lua files under the file, this can be changed, you need to use luaforwindow to execute

[plain] view plain copy

< /div>

< ol start="1" style="border-top:none;border-right:1px solid rgb(231,229,220);border-bottom:none;border-left:none;background-color:rgb(255,255,255);color:rgb (92,92,92);">

  • –dofile(“F:/Program_Files/Lua/lua_script/csvtolua/get_csv.lua”)
  • require”lfs”
  • functionfindindir(path,wefind,r_table,intofolder)
  • for file in lfs.dir(path) do
  • if file~=”.” and file~=”..”then
  • < li style="border-top:none;border-right:none;border-bottom:none;border-left:3px solid rgb(108,226,108);background-color:rgb(248,248,248);line-height:18px;list- style-position:outside;">local f = path..’\\’..file

  • –print (“/t”..f)
  • if string.find(f, wefind) ~= nil then
  • –print(“/t”..f)
  • table.insert(r_table,f)
  • end end
  • local attr=lfs.attributes(f)
  • assert (type(attr)==”table”)
  • Ifattr.mode==”directory”and intofolderthen /span>
  • findindir(f,wefind,r_table,intofolder) span>
  • else
  • –for name, value in pairs(attr) do do
  • print (name, value)
  • end end
  • < span style="border:none;color:#000000;background-color:inherit;">end end
  • end
  • end
  • local currentFolder=[[F:\Program_Files\Lua\lua_script\csvtolua]]
  • —————————- ———
  • local input_table = { }
  • findindir(currentFolder,”%.lua”, input_table, false)–Find the lua file, here you can change it
  • i=1
  • while input_table[i] ~=nil do
  • print(input_table[i])
  • i=i+ 1
  • end
  • < /ol>


    This is the result of execution:

    [plain] view plain < span> copy

    1. –dofile(“F:/Program_Files/Lua/lua_script/csvtolua/get_csv.lua”)
    2. require”lfs”
    3. functionfindindir(path,wefind,r_table,intofolder)
    4. for file in lfs.dir(path)
    5. if file~=”.” and file~=”..” then
    6. local f=path..’\\’..file< /li>
    7. –p rint(“/t”..f)
    8. if string.find(f, wefind) ~= nil then
    9. Print(“/t”..f)
    10. table.insert(r_table, f)
    11. end end
    12. local attr=lfs.attributes(f)
    13. Assert (type(attr)==”table”)
    14. ifattr.mode==”directory”and intofolderthen
    15. findindir(f,wefind,r_table,intofolder)
    16. < li style="border-top:none;border-right:none;border-bottom:none;border-left:3px solid rgb(108,226,108);background-color:rgb(248,248,248);line-height:18px;list- style-position:outside;"> else Else

    17. –for name, value in pairs(attr) do
    18. Print (name, value)
    19. end end< /li>
    20. end
    21.     end    
    22. end    
    23. local currentFolder = [[F:\Program_Files\Lua\lua_script\csvtolua]]   
    24. ————————————-    
    25. local input_table = {}    
    26. findindir(currentFolder, “%.lua”, input_table, false)–查找lua文件,这里可以改的  
    27. i=1    
    28. while input_table[i]~=nil do    
    29. print(input_table[i])    
    30. i=i+1    
    31. end    

    [plain]  view plain  copy

    [plain]  view plain  copy

    Leave a Comment

    Your email address will not be published.