diff -r 30d76ecdd725 -r e2face1be50e scan.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scan.lua Tue Mar 17 21:39:41 2009 +0200 @@ -0,0 +1,40 @@ +require('lfs') + +local function filtered_dir(d) + local f, s_, v_ = lfs.dir(d) + local function g(s, v) + while true do + local vn=f(s, v) + if vn~='.' and vn~='..' then + return vn + end + end + end + return g, s_, v_ +end + + +function scan(d) + local h={} + for f in filtered_dir(d) do + local n=d..'/'..f + local a=lfs.attributes(n) + if a.mode=='directory' then + local nh=scan(n) + h[n]=nh + elseif a.mode=='file' then + h[n]=true + end + end + return h +end + +function hfold(h, a, f, g) + for n, c in pairs(h) do + if type(c)=='table' then + hfold(c, f(a, n), f, g) + else + g(a, n) + end + end +end