Delete Files in Documents Directory

Few days before, I created two posts (permanently download Image & Locally cache mp3 file ) which stores data locally. Now, In this post, I am going to illustrate How to remove the all data which is into the Document directory.

I was also looking for a way to clean up the same directory when my device was not connected.

The first approach I took was to loop through all the files, building a path to each, one by one:

The code above works fine. However, I was interested in something that didn’t build each path separately – the code below deletes all the files.

Given the requested item to remove was a directory, as you’d expect, not only were the files deleted, so was the Documents directory. Problem is, I ran into errors when I attempted to drag/drop new files into the file sharing.

To get things working again, I changed up the code above to create the Documents directory:

Expected Output

Grab the Sample code  from here.

Leave a Reply

Your email address will not be published. Required fields are marked *