Playdate.file.delete() failing

I'm calling playdate.file.delete("store/store-1.json", false) in my game to reset the save game. This works fine in the simulator but fails on device.

  • "store" is the subdirectory where all the profiles are saved, created with playdate.file.mkdir("store/")
  • Files are written using json.encodeToFile("store/store-1.json", true, table) and write/read fine.
  • I confirm that playdate.file.exists("store/store-1.json") returns true before trying to delete(), which fails.

Any idea what's going on?

Try omitting the file extension.

playdate.file.delete("store/store-1", false)

Across the SDK there are some discrepancies as to whether the file extensions are needed, or not. If in doubt, try both ways.

Thanks for the suggestion but (thankfully) that doesn't seem to make any difference.

I was able to finally delete the file after restarting the Playdate.

Another part of my code does create a file object on the same path and never explicitly closes it. I assumed the Lua GC would close it eventually, or at least exiting the game would, but maybe not. Hopefully putting an explicit :close() in there will fix the problem.


It looks like that's the problem, unlike macOS the device filesystem won't let you delete an open file. That behavior doesn't appear to be configurable (and hacking it in seems like a bad idea) so as a first step I'll document that and add an error return to the function. Ultimately I'll add open file tracking to the simulator so we can replicate the behavior, but that might be a Part 2.

Thanks Dave. A docs update would be great and an error message would be even better.

I don't need the simulator file delete functionality on device but it's surprising that even closing/restarting the process apparently doesn't close the file handles.

1 Like