lua-users home
lua-l archive

How to sort the output of lfs.dir

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


 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

AltStyle によって変換されたページ (->オリジナル) /