Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to clear all files saved in system.DocumentsDirectory
Started by harrison.minibucks Jan 04 2020 03:40 AM

2 replies to this topic

Best Answer XeduR @Spyric , 04 January 2020 - 04:43 AM

You can use Lua File System for that.

 

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

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

harrison.minibucks

[GLOBAL: userInfoPane.html]
harrison.minibucks
  • Observer

  • 6 posts
  • Corona SDK

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()



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,249 posts
  • Corona SDK

  Best Answer

You can use Lua File System for that.

 

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


  • harrison.minibucks likes this

[TOPIC: post.html]
#3

harrison.minibucks

[GLOBAL: userInfoPane.html]
harrison.minibucks
  • Observer

  • 6 posts
  • Corona SDK

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



[topic_controls]
[/topic_controls]