Traverse directories under Windows use the LFS library: for example, traverse all files in the entire directory
Local LFS = require "LFS"
function Findpathname (path)
Local filetbl = {}
For file in Lfs.dir (path) does
If file ~= "." and File ~= ":" Then
filetbl[#fileTbl + 1] = File
End
End
Return FILETBL
End
To create a directory:
Local function Createpath (path)
Local TBL = lua_string_split (Path, "/")
Local str = ""
For k,v in Ipairs (TBL) do
if k = = 1 Then
str = String.Format ("%s", V)
Else
str = String.Format ("%s/%s", Str,v)
End
Lfs.mkdir (str)--Create Directory
Print (str)
End
End
function Lua_string_split (str, Split_char)--for splitting strings
Local sub_str_tab = {};
while (true) does
Local pos = String.find (str, split_char);
if (not POS) then
Local size_t = TABLE.GETN (Sub_str_tab)
Table.insert (SUB_STR_TAB,SIZE_T+1,STR);
Break
End
Local SUB_STR = String.sub (str, 1, pos-1);
Local size_t = TABLE.GETN (Sub_str_tab)
Table.insert (SUB_STR_TAB,SIZE_T+1,SUB_STR);
Local t = String.len (str);
str = string.sub (str, pos + 1, t);
End
return sub_str_tab;
End
Under the Linxu platform method, just the LFS library is replaced with LS library.
Reprint please indicate the source: from the blog Park Hemjohn
Lua's way of traversing directories under LINXU and Windows systems