Exporting files

I’m using Solar2d to build a character sheet app for an RPG. I save each sheet’s data as a json file, but as cross-device play is important, I’d like to be able to regularly save and retrieve these files from a system folder (which is linked to a cloud server, i.e. dropsync or drivesync).

pathForFile doesn’t let me escape the base directory of the file, which is not only inconvenient on a desktop, but apparently impossible on an Android.

Is such a thing possible, or am I screwed?

On Android and iOS, you should stick to using the Documents directory.

On Windows/Mac, you could also use documents directory, but if you want to save the files wherever you want on your computer, you can do so. If you run print( system.pathForFile() ) you see that it returns the project root path, but when you’re reading and writing files using io.*, for instance, you can just type in any filepath that you want (as long as you have read/write access).

You also have full access to os.execute and Lua file system, so you can do pretty much whatever you want with files like that.

I was recently looking into it as well for a personal Android app, even also planned to use dropsync/drivesync, and this plugin by @Scott_Harrison is probably our best bet on Android:
https://solar2dmarketplace.com/plugins?ExternalStorage_tech-scotth

Sadly I haven’t had the opportunity to test it myself yet due to a lack of time, but I’ve talked to Scott and there don’t seem to be any issues when it comes to our use case, at least in theory.

Hope it helps!

1 Like

Hah, I saw that too. Gonna try it out tomorrow, I’ll update you on my findings.

1 Like

After battling with the demo for a bit, I finally got it to not-work on my devices - Specifically the “make a folder” and “copy to SD” buttons/functions don’t actually do anything, although the former incorrectly returns a popup saying it’s successfully created a folder (it hasn’t, I’ve looked). sdCardPath returns a string (“no access”), and then contradicts itself by saying isWriteable.

Can’t recommend, unfortunately.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.