Can't delete files

I'm coding in lua and I have json files that the user can add to that will load into my app using a usb cord, but I wanted them to be able to delete json files from the app as well. It loads the json using this code: json.decodeFile(filePath)
and when I run this
print("File exists? "..tostring(playdate.file.exists(summary.filePath))) it says that file exists.... but if I run this
playdate.file.delete(summary.filePath, false) it doesn't actually delete the file and so I tried to run it again without the file extension
playdate.file.delete(summary.filePath:gsub("%.json$", ""), false) and that doesn't work as well.

I've tried this on the simulator and also on the device. It doesn't return any errors or anything. Anyone have any ideas? All these files are stored in files directory inside the pdx. An example of a file path is files/file.json

I don’t think you can alter files inside the PDX, so you’d need to store these files in your game’s Data directory. From the docs:

Behind the scenes, there are two directories your game has access to: the root of your app bundle (read-only), and a Data directory unique to your game (readable and writeable) where you can store your game’s saved state or other data.

Edit: so when you load the file over USB you’d put it in Data/[your bundle ID]/files/file.json, then the same code should be able to delete it.

1 Like