test_fs.lua 614 B

1234567891011121314151617181920212223
  1. function link_dir (dir, base)
  2. local path = base.."/"..dir
  3. local mode = lfs.attributes (path).mode
  4. if mode == "directory" then
  5. return string.format ('<a href="%s">%s</a>',
  6. cgilua.mkurlpath ("test_fs.lua", { dir = path }),
  7. dir)
  8. else
  9. return dir
  10. end
  11. end
  12. cgilua.htmlheader ()
  13. cgilua.put ("<h1>Testing Filesystem library</h1>\n")
  14. cgilua.put ("<table>\n")
  15. cgilua.put ("<tr><td colspan=2>Testing <b>dir</b></td></tr>\n")
  16. local i = 0
  17. local dir = cgi.dir or "."
  18. for file in lfs.dir (dir) do
  19. i = i+1
  20. cgilua.put ("<tr><td>"..i.."</td><td>"..link_dir(file, dir).."</td></tr>\n")
  21. end
  22. cgilua.put ("</table>\n")