中关村在线

首页 排行 新品 问答 下载 论坛 手机 笔记本 数码相机 主板 显卡 平板电脑 更多

android手机如何打开.lua文件?

举报
讨论回答 (6)
deathadders
jm5858
Freezing_star
用lua file system 这个库,在lua项目主页可以找到,或者去谷歌。
具体用法在它的说明文档里有。
你可以看这个库的例子,里面有教你查看文件的创建日期与修改日期。

下面是例子:

------------------------------------------------------
local tmp = "/tmp"
local sep = "/"
local upper = ".."

require"lfs"
print (lfs._VERSION)

function attrdir (path)
--这个就是你要的目录迭代器
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..sep..file

print ("\t=> "..f.." <=")
--这一行打印出所有文件,你可以改成你想要的
local attr = lfs.attributes (f)
assert (type(attr) == "table")
if attr.mode == "directory" then
attrdir (f)
else
for name, value in pairs(attr) do
print (name, value)
end
end
end
end
end

---下面是其他的例子,如获取文件属性

-- Checking changing directories
local current = assert (lfs.currentdir())
local reldir = string.gsub (current, "^.*%"..sep.."([^"..sep.."])$", "%1")
assert (lfs.chdir (upper), "could not change to upper directory")
assert (lfs.chdir (reldir), "could not change back to current directory")
assert (lfs.currentdir() == current, "error trying to change directories")
assert (lfs.chdir ("this couldn*t be an actual directory") == nil, "could change to a non-existent directory")

-- Changing creating and removing directories
local tmpdir = current..sep.."lfs_tmp_dir"
local tmpfile = tmpdir..sep.."tmp_file"
-- Test for existence of a previous lfs_tmp_dir
-- that may have resulted from an interrupted test execution and remove it
if lfs.chdir (tmpdir) then
assert (lfs.chdir (upper), "could not change to upper directory")
assert (os.remove (tmpfile), "could not remove file from previous test")
assert (lfs.rmdir (tmpdir), "could not remove directory from previous test")
end

-- tries to create a directory
assert (lfs.mkdir (tmpdir), "could not make a new directory")
local attrib, errmsg = lfs.attributes (tmpdir)
if not attrib then
error ("could not get attributes of file `"..tmpdir.."*:\n"..errmsg)
end
local f = io.open(tmpfile, "w")
f:close()

-- Change access time
local testdate = os.time({ year = 2007, day = 10, month = 2, hour=0})
assert (lfs.touch (tmpfile, testdate))
local new_att = assert (lfs.attributes (tmpfile))
assert (new_att.access == testdate, "could not set access time")
assert (new_att.modification == testdate, "could not set modification time")

-- Change access and modification time
local testdate1 = os.time({ year = 2007, day = 10, month = 2, hour=0})
local testdate2 = os.time({ year = 2007, day = 11, month = 2, hour=0})

assert (lfs.touch (tmpfile, testdate2, testdate1))
local new_att = assert (lfs.attributes (tmpfile))
assert (new_att.access == testdate2, "could not set access time")
assert (new_att.modification == testdate1, "could not set modification time")

local res, err = lfs.symlinkattributes(tmpfile)
if err ~= "symlinkattributes not supported on this platform" then
-- Checking symbolic link information (does not work in Windows)
assert (os.execute ("ln -s "..tmpfile.." _a_link_for_test_"))
assert (lfs.attributes"_a_link_for_test_".mode == "file")
assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link")
assert (os.remove"_a_link_for_test_")
end

if lfs.setmode then
-- Checking text/binary modes (works only in Windows)
local f = io.open(tmpfile, "w")
local result, mode = lfs.setmode(f, "binary")
assert((result and mode == "text") or (not result and mode == "setmode not supported on this platform"))
result, mode = lfs.setmode(f, "text")
assert((result and mode == "binary") or (not result and mode == "setmode not supported on this platform"))
f:close()
end

-- Restore access time to current value
assert (lfs.touch (tmpfile, attrib.access, attrib.modification))
new_att = assert (lfs.attributes (tmpfile))
assert (new_att.access == attrib.access)
assert (new_att.modification == attrib.modification)

-- Remove new file and directory
assert (os.remove (tmpfile), "could not remove new file")
assert (lfs.rmdir (tmpdir), "could not remove new directory")
assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == nil, "could create a directory inside a non-existent one")

-- Trying to get attributes of a non-existent file
assert (lfs.attributes ("this couldn*t be an actual file") == nil, "could get attributes of a non-existent file")
assert (type(lfs.attributes (upper)) == "table", "couldn*t get attributes of upper directory")

-- Stressing directory iterator
count = 0
for i = 1, 4000 do
for file in lfs.dir (tmp) do
count = count + 1
end
end
print"Ok!"
wodexingfune
s2673407022
zyx58451
展开查看全部 6 条讨论
相关问题

运行Lumion需要电脑什么配置?

1227 浏览 4 回答

扩展阅读

ALIENWARE外星人AW2725QF双模游戏显示器评测:打造极致视觉体验

评论 0

ALIENWARE外星人AW2725QF双模游戏显示器评测:打造极致视觉体验

DIY从入门到放弃:买二手显卡如何避坑?

评论 21

DIY从入门到放弃:买二手显卡如何避坑?

千元大屏电视大揭秘!选购攻略全在这里

评论 1

千元大屏电视大揭秘!选购攻略全在这里

揭秘苹果电视缺席真相:不赚钱只是一方面

评论 2

揭秘苹果电视缺席真相:不赚钱只是一方面

旗舰级与入门级相差几何?三款固态硬盘《黑神话:悟空》载入速度对比实测

评论 4

旗舰级与入门级相差几何?三款固态硬盘《黑神话:悟空》载入速度对比实测
热门问题

求推荐一款笔记本。工科研究生用,便于随身携带。平时做科研,处理数据,查阅文献。不玩网游和单机,至多玩棋牌游戏和影音。喜欢摄影,需要修图。附加:纠结要不要带数字键盘区。预算最多8000。尽量便宜些。

1.2万 浏览 6 回答

求推荐一款笔记本。工科研究生用,便于随身携带。平时做科研,处理数据,查阅文献。不玩网游和单机,至多玩棋牌游戏和影音。喜欢摄影,需要修图。附加:纠结要不要带数字键盘区。预算最多8000。尽量便宜些。

平面设计一个月工资一般多少

6520 浏览 5 回答

平面设计一个月工资一般多少

歪歪漫画免费页面看不了是为什么?

6775 浏览 6 回答

歪歪漫画免费页面看不了是为什么?

256gSSD是否够用?打算买个笔记本,办公为主,查阅文献等。不玩大型游戏,至多玩一些棋牌类游戏和影音娱乐。手里有2T移动硬盘,但也想在笔记本上存少量的电影。平时玩单反,处理图片比较多。

2.3万 浏览 4 回答

256gSSD是否够用?打算买个笔记本,办公为主,查阅文献等。不玩大型游戏,至多玩一些棋牌类游戏和影音娱乐。手里有2T移动硬盘,但也想在笔记本上存少量的电影。平时玩单反,处理图片比较多。

马斯克有华人血脉吗

8759 浏览 6 回答

马斯克有华人血脉吗

妖精动漫免费入口页面弹窗在哪

7371 浏览 5 回答

妖精动漫免费入口页面弹窗在哪

肿么找回QQ浏览器历史记录

7279 浏览 6 回答

肿么找回QQ浏览器历史记录

笔记本电脑可以连接到无线网络,但是显示无Internet,插网线也没办法上网

1.2万 浏览 7 回答

笔记本电脑可以连接到无线网络,但是显示无Internet,插网线也没办法上网

投诉京东商城的电话是多少?

4292 浏览 6 回答

投诉京东商城的电话是多少?

户户通客户服务热线是多少?

1.2万 浏览 9 回答

户户通客户服务热线是多少?
最新问答

电脑qq怎么调字体大小

6484 浏览 6 回答

电脑qq怎么调字体大小

笔记本电脑大写锁定键一直亮怎么处理?

5964 浏览 5 回答

笔记本电脑大写锁定键一直亮怎么处理?

游戏国际服是什么意思?

4285 浏览 6 回答

游戏国际服是什么意思?

为何我明明卸载了腾讯电脑管家却还是会出现

7904 浏览 6 回答

为何我明明卸载了腾讯电脑管家却还是会出现

excel中在表格中输入货号,自动填充成本价,怎么才能实现

770 浏览 4 回答

excel中在表格中输入货号,自动填充成本价,怎么才能实现
举报
举报成功

经过核实后将会做出处理,感谢您为社区和谐做出贡献。

请选择删除原因
删除成功
确定推荐该回答?
推荐成功

更多频道

频道导航
辅助工具