Delete folder with contents

I've made an app that lets you save the canvas into a mainfolder with a subfolder
mainfolder name is made by the app and the subfolder name is based on user input.

the pictures are saved within the subfolder

Is there a way to with the push of a button delete the subfolder and its contents?

with extensions:

When I try

I get "Sorry, can't delete a directory

Hi Eelko

I think you need to try with your App as an APK. Note also that you should put your main folder directly on the virtual SD drive and not in the App Inventor Companion path.

Its when I installed the .apk that I got the "sorry etc. message.

could you explain how I would save it to the virtual SD drive?
or point me in the right direction,

Thanks for the help.

See here: (you didn't read the documentation.....)!msg/mitappinventortest/Vw76t6XECiE/D7bre_epQowJ

See also:
Note that "sdcard" is the virtual sd on the device's memory drive. There are more hoops to jump through to save/delete files on a physical sd card.

When I try:

And install the .apk I dont get any sort of error message but I dont see any file/folder made on the SD card.
I was lookingfor "/sdcard/mainfolder/projectname/picturename.jpg"

@Eelko Check this: deleteFolder.aia (66.7 KB)

There is currently a bug (copy a file from the assets) with the FileTools ext. from @vknow360 that will be fixed soon, then you can do it all with one (his) extention.

But maybe you don't need the method copy files from assets to external storage. Then you can of course do it only with FileTools ext. from @vknow360. I need Taifun's ext. only for my example app (to copy the files from assets to /storage/emulated/0/myFolder).


See also here:

Hi @Anke
There is no need to get file list and delete files one by one.
Simply use file or folder name in FileTools.Delete method and it will do the rest.If path is a file then it will only delete that file but if it is a folder then it will delete all files first and then the folder.

@vknow360 I know that, but I want to show how to delete all files from a folder.
So I used both methods.

Btw, a added an aia, so @Eelko can check it.

1 Like

Thank you,
It should be clear that I dont have a background in coding or anything so I might be missing out on something obvious here.
I've added this to the initialize image
Thinking it will prompt and request premission which is does, so thats cool.

I've set the save location to image
I'm uncertain about the placement of the dashes in this but it does work when I save canvas I get a row of folders in folder's storage-emulated-0-mainfolder and then the folder based on user imput : projectname.

the picture based on mmdd and puntnumber.jpg gets saved in there all fine and good so far.

I've tryed doing this:
but that doesnt work, gives a message that is does not exists.

then I tryed

Also copied from youre examle.
I changed the directory name and the extension to false thinking as its a folder I want to delete there is no extension.
But this again does not work.

it was mentioned before that it would benifit me to store the data on physical sd card but I dont have on in my phone so I would like to be able to do this on the internal storage

This works for me:

As previously indicated, you have to delete all the files inside a folder before you can delete the folder.
The TaifunFile extension returns a full path to each file, this needs to be modified to a relative path before it can be deleted. The example assumes no subdirectories. If you have subdirectories, then create a routine to delete each of these (and the files within them) before trying to delete the top level directory.

the Delete method of my extension is restricted to delete only empty directories...

there once was a guy who deleted his complete internal sdcard while testing the Delete method of the FileTools extension... be careful...


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

I believe the same applies to the file component delete block which I also tested

I think that was because of using empty string.At that time 'absoluteFilePath' (which creates absolute file path from relative file path) method was returning external storage's path for empty string but after his issue I fixed that and now it returns empty string for empty string.
So now there should not be any issue in using that method :grin: