Is there a way to read/write files & folders with OpenFL 4.4.1?

In my app, using OpenFL 4.4.1, I do System.applicationStorageDirectory (with lime.system.System) to get the %storageDirectory%/Company/Appname path.

However, I am trying to find a way to create a folder under that directory, check if files exist and read/write text and bytes to files in there for savestates and config files.

Basically I’d need filesystem functionality like
file->read/write/delete/rename/getsize/exists
folder->create/rename/delete/exists

I am trying to find out how to do this for a while now. I noticed OpenFL 4 doesn’t have a filesystem class of sorts. Is this not implemented, not planned or do I need to do it some other way? I don’t want to use sharedobjects by the way.

Take a look here: http://api.haxe.org/sys/FileSystem.html

I hope it helps you.

1 Like

You’ll also want to look at sys.io.File

http://api.openfl.org/sys/io/File.html

Quick tip, the openfl.utils.ByteArray class converts to/from the haxe.io.Bytes class, so you can pass and receive ByteArray directly from these APIs

1 Like

Nice thanks, these seem ideal, thought they don’t seem to work on html5 and flash, but I suppose that’s expected since these do not have free access to the OS filesystem anyway. I think I could use SharedObject for these two if html5 maps to localstorage.

I think I’ll mainly need to read/write text, might need bytearray for doing a xor crypt, just to have a little foolproof layer on savedata and such akin to SharedObject.

Yeah, SharedObject should work on all platforms, and is the simple save solution, but writing to files directly on the desktop will give you more control :slight_smile:

1 Like

Ah great to know, yeah I’d like a little bit control over desktop/mobile/console etc. targets, e.g. I do like how I can specify a company and appname to be used as directories and so far the %appdata% location on Windows looks ideal (which is the intended directory for Application Storage anyway, hate when apps pollute the system directories with random folders).