lfs库是很好的选择,可惜不会编译,无奈只能自己写个简单的lua库。代码如下:
#include
#include
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
static int
DirFiles(lua_State *L){
long Handle;
struct _finddata_t FileInfo;
size_t l;
int index = ;
const char* path = luaL_checklstring(L, , &l);
lua_newtable(L);
if ((Handle = _findfirst(path, &FileInfo)) != -1L)
{
lua_pushstring(L, FileInfo.name);
lua_seti(L, -, ++index);
while(_findnext(Handle, &FileInfo) == )
{
lua_pushstring(L, FileInfo.name);
lua_seti(L, -, ++index);
}
_findclose(Handle);
}
return ;
}
int
luaopen_lfs(lua_State *L){
luaL_checkver