首先用lua遍历目录:

 function getDirs(path)
local s = {}
function attrdir(p)                  
for file in lfs.dir(p) do
if file ~= "." and file ~= ".." then
local f = p .. file
local attr = lfs.attributes (f)
if attr.mode == "directory" then
table.insert(s, f)
attrdir(f .. "/")
else
table.insert(s, f)
end
end
end
end
attrdir(path)
return s
end

  然后将结果打包成JSON格式用于传递:

 function string2JSON(path)
local s = getDirs(path)
local cjson = require("cjson")
local sJson = cjson.encode(s)
return sJson
end

  最后用lwt后台输出到页面中:

 require "httpd"
require "lfs" request, args = ... function getDirs(path)
local s = {}
function attrdir(p)
for file in lfs.dir(p) do
if file ~= "." and file ~= ".." then
local f = p .. file
local attr = lfs.attributes (f)
if attr.mode == "directory" then
table.insert(s, f)
attrdir(f .. "/")
else
table.insert(s, f)
end
end
end
end
attrdir(path)
return s
end function string2JSON(path)
local s = getDirs(path)
local cjson = require("cjson")
local sJson = cjson.encode(s)
return sJson
end httpd.set_content_type("text/plain")
httpd.write(string2JSON(request.filedir))

【Lua】LWT遍历指定目录并输出到页面中的更多相关文章

  1. 【Lua】遍历目录结果输出到页面中,刷新页面后出现500 Internal Server Error

    在通过lua获取目录json字符串,然后作为数据源,通过Extjs生成树的过程中,发生了一个奇怪的问题,那就是获取目录json字符串然后传递给Extjs生成树的这个过程中,一开始都是很顺利的就生成了, ...

  2. [WinAPI] API 13 [遍历指定目录 打印文件和其他属性]

    Windows API中,有一组专门的函数和结构,用于遍历目录,它们是FindFirstFile函数.FindNextFile函数和WIN32_FIND_DATA结构.使用FindFirstFile和 ...

  3. PHP遍历指定目录,并存储目录内所有文件属性信息

    项目需要,需要写一个函数,能够遍历指定目录中的所有文件,而且这个目录中的子目录也要遍历.输出文件的属性信息,并存储. 想想需求,不就是一个ls -al命令吗,实现获取相关属性就好了,再加上一个遍历OK ...

  4. python遍历一个目录,输出所有文件名

    python遍历一个目录,输出所有文件名 python os模块 os import os  def GetFileList(dir, fileList):  newDir = dir  if os. ...

  5. delphi遍历指定目录下指定类型文件的函数

    遍历指定目录下指定类型文件的函数// ================================================================// 遍历某个文件夹下某种文件,/ ...

  6. Python —— 批量替换指定目录下的所有文件中指定字符串

    参考:http://blog.csdn.net/zcwfengbingdongguke/article/details/13951527 代码: #!/usr/bin/python import os ...

  7. js引入php 用来加载静态页面 输出到页面中

    HTML页面中加入代码 <script type="text/javascript" src="http://www.域名.com/js.php?id=tjyd&q ...

  8. 【Lua】Lua + LWT + ExtJS构建目录树

    Lua处理后台逻辑,Lua lwt搭建后台程序,ExtJS根据后台传来的json数据构建目录树. 前台html和ExtJS代码不用多讲,直接上代码: treePanel.html <html&g ...

  9. java-IO流(File对象-深度遍历指定目录下的文件夹和文件)

    需求:遍历这个树状结构 File(String pathname) '\\'为了转义'\' // 通过抽象路径pathname 创建一个新的文件或者目录 File parent = new File( ...

随机推荐

  1. getpost请求

    // GET请求与获取结果 /// </summary> public static string HttpGet(string Url, string postDataStr) { Ht ...

  2. selenium爬取网易云

    from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.c ...

  3. html5 表格标签 table tr td

      最重要的三个 <table>     表格声明标签 属性: boarder    边框粗细 style    可配合css 使用 <tr>    行标签 table row ...

  4. 927. Three Equal Parts

    Given an array A of 0s and 1s, divide the array into 3 non-empty parts such that all of these parts ...

  5. [agc004f]Namori 贪心

    Description ​ 现在给你一张NN个点MM条边的连通图,我们保证N−1≤M≤NN−1≤M≤N,且无重边和自环. ​ 每一个点都有一种颜色,非黑即白.初始时,所有点都是白色的. ​ 想通过执行 ...

  6. [ActionScript 3.0] 创建倒影

    package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Display ...

  7. NSScanner 扫描字符串

    两个常用于扫描字符串的方法 //'指针'只移动一个位置,判断当前所指的字符是否是目标字符@"x", 若是则存入result中,返回YES,否则NO BOOL res = [scan ...

  8. ModuleNotFoundError: No module named 'Crypto'

    pycrypto已经舍弃了使用pycryptodome,pip uninstall pycrypto,然后安装pycryptodome,pip install pycryptodome 可能还需要改名 ...

  9. git.exe 妙用

    1.如果 window 上的命令行,在进行编译的不好使 可以尝试在git 中运行 2.运行 python 脚本 ,保持脚本一直执行(尤其是中间出错) 可以做一个 sh 文件,然后在git 中运行 #! ...

  10. oracle nvl()函数

    oracle的nvl()函数作用是当第一个值不为null时,返回第一个值,否则返回第二个值. 当第一个值为一个运算表达式时,那么第二个的值被限定为只能是NUMBER类型或者能隐式转换为NUMBER类型 ...