首先用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. strncmp用法说明

    函数原型 int strcmp(char *str1,char * str2,int n) 功能 比较字符串str1和str2的前n个字符. 头文件 #include <string.h> ...

  2. zigzag数组实现

    题目出自面试宝典8.3.2 题目描述: 输入n,求一个n*n的矩阵,规定矩阵沿45度线递增,形成一个zigzag数组(JPEG编码里去像素数据的排列顺序),请问如何用C++实现? 例如: n=2 0 ...

  3. Verilog MIPS32 CPU(五)-- CP0

    Verilog MIPS32 CPU(一)-- PC寄存器 Verilog MIPS32 CPU(二)-- Regfiles Verilog MIPS32 CPU(三)-- ALU Verilog M ...

  4. 使用PowerShell自动部署ASP.NetCore程序到IIS

    Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能.有关于更多PowerShell的信息,可参阅百度词条 接 ...

  5. C# 调用C++动态库注意事项

    C# 调用C++动态库注意事项 最近项目上需要在C#中调用C++,期间遇到不少坑,总结如下: 1.in const char*   对应C#中string 或  IntPtr 2.out const ...

  6. django 生命周期

    客户端发送请求 客户端(浏览器) → 发送请求 → 服务器(wsgi) → 解析请求 → 服务器(Middleware) → process_request → 服务器(urls) → 通过路由寻vi ...

  7. sharepoint 2010 GetUserProfileByName 5566

    After some further investigation i found that it's actually the "ASP.NET Impersonation" th ...

  8. 网易严选的wkwebview测试之路

    本文来自网易云社区 作者:孙娇 UIWebView是苹果继承于UIView封装的一个加载web内容的类,它可以加载任何远端的web数据展示在你的页面上,你可以像浏览器一样前进后退刷新等操作.不过苹果在 ...

  9. 微信小程序的onLaunch()方法和onShow()方法

    在app.js里面你会发现一个onLaunch()方法,这个方法是当小程序加载完毕后就执行的方法,此外,还有一个onShow()方法,先看下面的代码 app.js //app.js App({ onL ...

  10. leecode刷题(12)-- 整数反转

    leecode刷题(12)-- 整数反转 整数反转 描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: - ...