How to clear all files saved in system.DocumentsDirectory

I have saved a few json files in the DocumentsDirectory path but now I want to create a function that will remove all files I’ve saved (Where different users have different file names)

local function clearCache() local allFiles = getAllFilesInPath(system.DocumentsDirectory) for i = #allFiles, 1, -1 do os.remove(allFiles[i]) end end

I would probably need something like the above?

Either remove all files inside, or get all the file names in the directory.

*Edit: Help needed to form this function getAllFilesInPath()

You can use Lua File System for that.

See https://docs.coronalabs.com/guide/data/LFS/index.html

Thanks, I got it working using this

local lfs = require( "lfs" ) local function clearCache() local path = system.pathForFile( nil, system.DocumentsDirectory ) for file in lfs.dir( path ) do os.remove(system.pathForFile( file, system.DocumentsDirectory )) end end