AP_Scripting: added isdirectory()

This commit is contained in:
Andrew Tridgell committed 2023-12-11 18:00:38 +11:00
1 parent 9065baa329
commit 3446ff78d7
4 files changed
+26

No files matched your search

+19
View File
@@ -720,6 +720,25 @@ int lua_dirlist(lua_State *L) {
return 1; /* table is already on top */
}
/*
return true if path is a directory
*/
int lua_isdirectory(lua_State *L) {
binding_argcheck(L, 1);
const char *path = luaL_checkstring(L, 1);
struct stat st;
if (AP::FS().stat(path, &st) != 0) {
lua_pushnil(L); /* return nil and ... */
lua_pushstring(L, strerror(errno)); /* error message */
return 2;
}
bool ret = (st.st_mode & S_IFMT) == S_IFDIR;
lua_pushboolean(L, ret);
return 1;
}
/*
remove a file
*/