Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local forFiles = function(path,pattern)
- if not path:sub(-1,-1):match("[\\/]") then
- path = path.."/"
- end
- local finddata_t = alien.defstruct{
- {"attrib","uint"},
- {"time_create","long"},
- {"time_access","long"},
- {"time_write","long"},
- {"size","ulong"},
- {"name","char"},
- }
- finddata_t.size = finddata_t.size+260
- local _finddata_t = finddata_t:new()
- local function getfilename(fd)
- local out = {}
- local offset = finddata_t.offsets.name
- local buf = fd()
- for i = offset+1, offset+260 do
- local c = buf:get(i, "char")
- if c > 0 then out[#out+1] = string.char(c)
- else break end
- end
- return table.concat(out)
- end
- local _findfirst = alien.MSVCRT._findfirst
- local _findnext = alien.MSVCRT._findnext
- local _findclose = alien.MSVCRT._findclose
- _findfirst:types{ret="long",abi="cdecl", "string","pointer"}
- _findnext:types{ ret="int", abi="cdecl", "long", "pointer"}
- _findclose:types{ret="int", abi="cdecl", "long"}
- hFile = _findfirst(path..pattern,_finddata_t());
- local tFiles = {}
- if hFile ~= -1 then
- tFiles[getfilename(_finddata_t)] = {
- ["attrib"] = _finddata_t.attrib,
- ["time_create"] = _finddata_t.time_create,
- ["time_access"] = _finddata_t.time_access,
- ["time_write"] = _finddata_t.time_write,
- ["size"] = _finddata_t.size,
- }
- local iRes = _findnext(hFile,_finddata_t())
- while iRes == 0 do
- tFiles[getfilename(_finddata_t)] = {
- ["attrib"] = _finddata_t.attrib,
- ["time_create"] = _finddata_t.time_create,
- ["time_access"] = _finddata_t.time_access,
- ["time_write"] = _finddata_t.time_write,
- ["size"] = _finddata_t.size,
- }
- iRes = _findnext(hFile,_finddata_t())
- end
- _findclose(hFile)
- end
- return tFiles
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement