Getting a list of files in assets directory at runtime?

Hi all! :slight_smile:

In my app I load an XML file via an HttpClient call. The path to the file is hardcoded as /assets/data/<filename.xml> and retrieving it works fine. I’d like to create an ion-select that lets the user select which XML file they want to load, but getting a list of files in my assets/data directory at runtime has proven difficult because I don’t know where the assets directory ends up at runtime. I’ve tried at least 5 different ways to get a file listing (i.e. ‘fs’, ‘listFiles’, ‘FileSystem’, ‘glob’, ‘globby’), but fs/listFiles/FileSystem each requires you to tell them where you want to look, as you might imagine. The glob related packages raise TONS of “can’t resolve ‘fs’” issues.

Can anyone assist me in finding out where assets wind up at runtime? I might be able to use one of the fs/listfiles/FileSystem options if I just knew where to look relative to my running app. A picture of the runtime filesystem would help!



You can’t.

Just put a json with the list of items in assets. And if you want to go fancy, generate that file using a script you call using one of the build hooks.

1 Like

To elaborate a bit on @Tommertom’s answer, the assets folder is a fiction at runtime. It is actually bundled within the app binary itself, so no filesystem operations can see it at all.

Thanks, Robert and Tom! That makes perfect sense - a known file I can open and read that lists the XML files in the dir, then I can select one and open it as I do now. Much appreciated.