[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to sort the output of lfs.dir
- From: Mingranina Gingranina <mingranina@...>
- Date: Sun, 9 Oct 2016 04:12:49 +0330
Dear Boris Nagaev and Rena,
Hello,
Many thank for your reply. That solved my problem.
Yours,
Mingranina
On 10/8/16, Rena <hyperhacker@gmail.com> wrote:
> On Sat, Oct 8, 2016 at 9:55 AM, Mingranina Gingranina
> <mingranina@gmail.com>
> wrote:
>
>> Dear List,
>> Hello,
>>
>> In the following function defined in Fontsampler for quick overview
>> of all fonts in a directory hierarchy, I need the output to be sorted
>> alphabetically. How can I do that?
>>
>> function dirtree(dir)
>> assert(dir and dir ~= "", "directory parameter is missing or empty")
>> if string.sub(dir, -1) == "/" then
>> dir=string.sub(dir, 1, -2)
>> end
>>
>> local function yieldtree(dir)
>> for entry in lfs.dir(dir) do
>> if not entry:match("^%.") then
>> entry=dir.."/"..entry
>> if not lfs.isdir(entry) then
>> coroutine.yield(entry,lfs.attributes(entry))
>> end
>> if lfs.isdir(entry) then
>> yieldtree(entry)
>> end
>> end
>> end
>> end
>>
>> return coroutine.wrap(function() yieldtree(dir) end)
>> end
>>
>> Any help would be gratefully appreciated.
>>
>> Thanks,
>> Mingranina
>>
>>
> Add the files to a table, then use table.sort().
>
> --
> Sent from my Game Boy.
>