I used to use NW.js for file operations, but recently tried out FileSystem so that I can support WebView2.
Technically, there's nothing that's not doable with FileSystem, but the workflow felt cumbersome.
- 'List contents' has to be run before 'Has file/folder' can be done.
- You have to 'List contents' even for known directories like "<documents>"
- 'Has file/folder' cannot be done with a folder path afaik, you have to 'List contents' again if you want a subfolder.
- To read any file, you need another event, 'On file operation complete'
- You can't send any data with the read file operation, nor get the name or location of the file. The only data available is FileSystem.FileText
- If the FileTag of the file operation is varying or unknown, you need to use 'On any file operation complete' and then compare the FileTag. I found the workaround of setting the FileTag to something like...
"readFile " & fileName & " " & fileDir
...to be a good way to send data with the request, then I can get these values with tokenat(FileSystem.FileTag, n, " ")
The reason I need more data with read file operations is because I have worked on a few games with level editors, and on a recent one, user levels are saved in a location and the player can make as many as they want. Since I don't know how many levels they may have, loading these levels into the in-game UI becomes a little more complicated. I've also experimented with making games moddable, where levels might be loaded from lots of JSON files and assets.
In any case where the amount of files is unknown, it becomes more annoying to work with FileSystem.
NW.js's workflow was very compact and easy in comparison, even ignoring the fact that it's synchronous.