|
1 require('lfs') |
|
2 |
|
3 local function filtered_dir(d) |
|
4 local f, s_, v_ = lfs.dir(d) |
|
5 local function g(s, v) |
|
6 while true do |
|
7 local vn=f(s, v) |
|
8 if vn~='.' and vn~='..' then |
|
9 return vn |
|
10 end |
|
11 end |
|
12 end |
|
13 return g, s_, v_ |
|
14 end |
|
15 |
|
16 |
|
17 function scan(d) |
|
18 local h={} |
|
19 for f in filtered_dir(d) do |
|
20 local n=d..'/'..f |
|
21 local a=lfs.attributes(n) |
|
22 if a.mode=='directory' then |
|
23 local nh=scan(n) |
|
24 h[n]=nh |
|
25 elseif a.mode=='file' then |
|
26 h[n]=true |
|
27 end |
|
28 end |
|
29 return h |
|
30 end |
|
31 |
|
32 function hfold(h, a, f, g) |
|
33 for n, c in pairs(h) do |
|
34 if type(c)=='table' then |
|
35 hfold(c, f(a, n), f, g) |
|
36 else |
|
37 g(a, n) |
|
38 end |
|
39 end |
|
40 end |