MATLAB: How to tell rmdir to stop

delete filesrmdir

Hi,
I wrote a program which saves images to a folder. Before the pictures are taken and saved I use rmdir(Foldername,'s') to remove the folder and files. Then I recreate the folder with mkdir(foldername).
Everything seems to be working while saving the pictures, however after I stop saving pictures, the pictures are deleted.
If don't use rmdir the pictures stay and are overridden in the process.
Is there any way to clear the images before I start saving neu ones?

Best Answer

You could delete the files instead of the directory. For example,
delete( fullfile(Foldername, '*.jpg') )