Here's some old code I found in my projects folder, I can't rember where it originated from. Anyhoo, it should be enough to get you started down the right path
require("lfs")
workingdir="C:/"print(workingdir.." contains:")local files ={
dircount =0,
filecount =0,
dirlist={},
filelist={}}
files.dirlist[0]="hi there"print(files.dirlist[0])for file in lfs.dir(workingdir)doif lfs.attributes(workingdir..file,"mode")=="file"then-- process file foundprint("file: "..file)
files.filelist[files.filecount]= file
files.filecount = files.filecount + 1elseif lfs.attributes(workingdir..file,"mode")=="directory"then-- process dir foundprint("dir: "..file)
files.dirlist[files.dircount]= file
files.dircount = files.dircount + 1endendprint()print("DIRECTORIES (" .. files.dircount .. ")")for f =0, files.dircount - 1doprint(files.dirlist[f])endprint()print("FILES (" .. files.filecount .. ")")for f =0, files.filecount - 1doprint(files.filelist[f])end
function attrdir(xpath, xtable)if application:getDeviceInfo()=="Web"then-- xpath = application:getNativePath(xpath)for file in lfs.dir(xpath)dolocal f = xpath..'/'..file
local attr = lfs.attributes(f)if attr.mode =="file"thentable.insert(xtable, f)endendelse-- desktopsfor file in lfs.dir(xpath)dolocal f = xpath..'/'..file
local attr = lfs.attributes(f)if attr.mode =="file"thentable.insert(xtable, f)endendendendlocal t ={}
attrdir("gfx/images", t)-- folder to fetch images from
I have this error: [string "tiled/tiled_levels.lua"]:91: cannot open gfx/images: No such file or directory stack traceback: [string "tiled/tiled_levels.lua"]:91: in function attrdir [string "tiled/tiled_levels.lua"]:911: in function init ...
This works fine on android and windows.
note: I will try to add / at the end of the path
EDIT: do you have a solution to this question without using LFS?
In HTML export, all your assets are packed into a single file (the .GApp) file, so not directly visible on the pseudo FS exposed to LFS, but you have access to the GApp file itself with lua (/main.GApp), so you could read the list of all files in your app from there. Here is the how Gideros reads it at app start: https://github.com/gideros/gideros/blob/master/emscripten/applicationmanager.cpp#L859 It should be as easy as reading the first four bytes of the GApp file into an uint32, using the value as an offset in the GApp file, and start reading zerto terminated file name strings from there, ending with an empty name.
Comments
I've seen the lfs project, but it looked like it wouldn't support Android/iOS; however I could be wrong about that?
Likes: antix
for in app paths see here http://docs.giderosmobile.com/file_system.html
In my experience you can also use:
/sdcard/ (and subdirs) in android
and
drive_letter:/ (and subdirs) on PC/windows
(check it in tntfx > "import json" or "import background" )
I have this code:
[string "tiled/tiled_levels.lua"]:91: cannot open gfx/images: No such file or directory
stack traceback:
[string "tiled/tiled_levels.lua"]:91: in function attrdir
[string "tiled/tiled_levels.lua"]:911: in function init
...
This works fine on android and windows.
note: I will try to add / at the end of the path
EDIT: do you have a solution to this question without using LFS?
Thank you
Here is the how Gideros reads it at app start: https://github.com/gideros/gideros/blob/master/emscripten/applicationmanager.cpp#L859
It should be as easy as reading the first four bytes of the GApp file into an uint32, using the value as an offset in the GApp file, and start reading zerto terminated file name strings from there, ending with an empty name.
Likes: MoKaLux