Lua's way of traversing directories under LINXU and Windows systems

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.