【Lua】LWT遍历指定目录并输出到页面中
首先用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遍历指定目录并输出到页面中的更多相关文章
- 【Lua】遍历目录结果输出到页面中,刷新页面后出现500 Internal Server Error
在通过lua获取目录json字符串,然后作为数据源,通过Extjs生成树的过程中,发生了一个奇怪的问题,那就是获取目录json字符串然后传递给Extjs生成树的这个过程中,一开始都是很顺利的就生成了, ...
- [WinAPI] API 13 [遍历指定目录 打印文件和其他属性]
Windows API中,有一组专门的函数和结构,用于遍历目录,它们是FindFirstFile函数.FindNextFile函数和WIN32_FIND_DATA结构.使用FindFirstFile和 ...
- PHP遍历指定目录,并存储目录内所有文件属性信息
项目需要,需要写一个函数,能够遍历指定目录中的所有文件,而且这个目录中的子目录也要遍历.输出文件的属性信息,并存储. 想想需求,不就是一个ls -al命令吗,实现获取相关属性就好了,再加上一个遍历OK ...
- python遍历一个目录,输出所有文件名
python遍历一个目录,输出所有文件名 python os模块 os import os def GetFileList(dir, fileList): newDir = dir if os. ...
- delphi遍历指定目录下指定类型文件的函数
遍历指定目录下指定类型文件的函数// ================================================================// 遍历某个文件夹下某种文件,/ ...
- Python —— 批量替换指定目录下的所有文件中指定字符串
参考:http://blog.csdn.net/zcwfengbingdongguke/article/details/13951527 代码: #!/usr/bin/python import os ...
- js引入php 用来加载静态页面 输出到页面中
HTML页面中加入代码 <script type="text/javascript" src="http://www.域名.com/js.php?id=tjyd&q ...
- 【Lua】Lua + LWT + ExtJS构建目录树
Lua处理后台逻辑,Lua lwt搭建后台程序,ExtJS根据后台传来的json数据构建目录树. 前台html和ExtJS代码不用多讲,直接上代码: treePanel.html <html&g ...
- java-IO流(File对象-深度遍历指定目录下的文件夹和文件)
需求:遍历这个树状结构 File(String pathname) '\\'为了转义'\' // 通过抽象路径pathname 创建一个新的文件或者目录 File parent = new File( ...
随机推荐
- SPOJ - AMR11J ——(BFS)
The wizards and witches of Hogwarts School of Witchcraft found Prof. Binn's History of Magic lesson ...
- 安装pygame for Python3.5
首先进入pygame官网下载页面:http://www.pygame.org/download.shtml 页面上提供的有py2.4-py2.7,py3.1-py3.2的版本(py2.4就是对应py ...
- 通过python实现wc基本功能
---恢复内容开始--- 1.Github项目地址: https://github.com/zhg1998/ww/blob/master/wc.py 2.项目相关要求: 写一个命令行程序,模仿已有wc ...
- Transaction And Lock--由Lookup导致的死锁情况
存在这样情况:1.表TB1有一列建立索引2.事务A对表进行更新,先获取对表的X锁以更新基本表中数据,然后对索引申请X锁以更新索引数据.3.事务B对表进行更新,先获取索引上S锁以使用索引进行Loopup ...
- c# 类的反射实例 (GetType().Invoke().GetMethod().CreateInstance())
原文:http://www.cnblogs.com/chenwei19/archive/2009/02/04/1384034.html Class1和Form 窗体在同一个命名空间 using Sys ...
- solr7.3集群搭建
solr集群搭建 原博客:https://blog.csdn.net/gdsgdh308227363/article/details/81004706 注意,在搭建solr集群前,建议最好有一个sol ...
- H5活动产品设计指南基础版
本文来自 网易云社区 . H5一般页面不会很多,看似简单,实际上会有很多细节需要注意,我自己在做过了几个H5之后,发现了一些常犯的问题,做了小结,希望给新开始做H5的产品相关的同学提供一些帮助. 首 ...
- 企业库连接形式简单例子记录 EnterpriseLibrary.Data
结构图 webconfig 配置正确的连接字符串 <connectionStrings> <add name="DBConnection" connectionS ...
- OCP题库变更,052新加的考试题及答案整理-22题
22.You are planning a software installation for both Oracle Database 11g Release 1 and Release 2. Yo ...
- [ActionScript 3.0] PrintJob打印功能
package { import flash.display.Bitmap; import flash.display.Sprite; import flash.events.MouseEvent; ...