lua遍历文件夹

1.遍历文件下所有的lua文件,这个可以改的,要用luaforwindow,才能执行

[plain]  view plain  copy
  1. --dofile("F:/Program_Files/Lua/lua_script/csvtolua/get_csv.lua")  
  2. require"lfs"    
  3. function findindir (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    
  12.             local attr = lfs.attributes (f)    
  13.             assert (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    
  20.             end    
  21.         end    
  22.     end    
  23. end    
  24. local currentFolder = [[F:\Program_Files\Lua\lua_script\csvtolua]]   
  25. -------------------------------------    
  26. local input_table = {}    
  27. findindir(currentFolder, "%.lua", input_table, false)--查找lua文件,这里可以改的  
  28. i=1    
  29. while input_table[i]~=nil do    
  30. print(input_table[i])    
  31. i=i+1    
  32. end    

这是执行的结果:

猜你喜欢

转载自blog.csdn.net/u012252959/article/details/80491776