List 我如何将目录排序到列表的顶部,而不必在lua中更改列表(现在按字母顺序排序)

List 我如何将目录排序到列表的顶部,而不必在lua中更改列表(现在按字母顺序排序),list,sorting,lua,List,Sorting,Lua,这是我的代码,它遍历每个项目,然后打印项目,如果它是一个文件,它会打印文件有多大,它会改变文本颜色,这取决于它是否是一个目录,但我也希望目录在顶部,但我不知道如何做,所以我需要一些帮助 if command == "dir" then local filelist = fs.list("") for _, file in pairs(filelist) do if fs.isDir(file) == true then

这是我的代码,它遍历每个项目,然后打印项目,如果它是一个文件,它会打印文件有多大,它会改变文本颜色,这取决于它是否是一个目录,但我也希望目录在顶部,但我不知道如何做,所以我需要一些帮助

if command == "dir" then
        local filelist = fs.list("")
        for _, file in pairs(filelist) do
            if fs.isDir(file) == true then
                term.setTextColor(8)
                print(file)
                term.setTextColor(colors.yellow)
            else
                term.setTextColor(1)
                print(file.." "..fs.getSize(file))
            end
        end
    end

我做到了我做到了我让它工作了
if command == "dir" then
        local filelist = fs.list("")
        for _, file in pairs(filelist) do
            if fs.isDir(file) == true then
                term.setTextColor(8)
                print("- "..file)
                term.setTextColor(colors.yellow)
            end
        end
        for _, file in pairs(filelist) do
            if fs.isDir(file) == false then
                term.setTextColor(2)
                print("- "..file.." "..fs.getSize(file).." bytes")
                term.setTextColor(colors.yellow)
            end
        end
    end