22 lines
692 B
Lua
22 lines
692 B
Lua
|
local r = fm.getRequest()
|
||
|
local function isSpecial(name)
|
||
|
return name == "." or name == ".." or string.sub(name, 1, 1) == "$"
|
||
|
end
|
||
|
local dirpath = r.params.dirpath
|
||
|
local files, directories = {}, {}
|
||
|
for name, kind in assert(unix.opendir(dirpath)) do
|
||
|
if not isSpecial(name) then
|
||
|
local file = { name = name, path = path.join(dirpath, name) }
|
||
|
if kind == unix.DT_REG then
|
||
|
table.insert(files, file)
|
||
|
elseif kind == unix.DT_DIR then
|
||
|
table.insert(directories, file)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
local function compareName(f1, f2)
|
||
|
return f1.name < f2.name
|
||
|
end
|
||
|
table.sort(directories, compareName)
|
||
|
table.sort(files, compareName)
|
||
|
fm.render("fragment/dirlist", { files = files, directories = directories })
|