문제

How can I check in Lua if a string is the path to an executable file? It seems that neither the standard library nor, surprisingly, LuaFileSystem provides a way to do this.

도움이 되었습니까?

해결책

LuaFileSystem has the lfs.attributes() function which returns a table. That, rather perversely, has a key named "mode" which contains a string describing the "type" of node (file, directory, socket, etc).

Although it's not listed in the manual at: http://keplerproject.github.io/luafilesystem/manual.html ... which seems to be the canonical reference for that module ... there is also a 'permissions' key in that table. I think you could parse it for any "x" characters.

I discovered this with:

#!lua 
local lfs = require 'lfs'
attr = lfs.attributes('./some_file')
for name, value in pairs(attr) do
    print (name,value)
    end

다른 팁

luaposix has the stat function. It returns a number for the mode field which includes execute permission bits (unlike LuaFileSystem which only gives you the file type.)

There is also access which will check permissions for only the current user.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top