Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing content from folder in matlab

In the matlab code I am generating files at after specific iterations in a file called 'results' in present working directory. When I want to run the code next time, files crated by previous run are also present in the results folder. In C I would do that as

(void) system("rm -rf results/*");

How can I remove content of folder 'results' every time code starts to execute? Thanks.

like image 953
alekhine Avatar asked Dec 27 '22 15:12

alekhine


2 Answers

system('rm -rf results/*') should be exactly the same as your C code.

like image 135
Joze Avatar answered Jan 04 '23 10:01

Joze


Alternatively, you can also use the built-in rmdir() function with the s argument to remove all subfolders and files in the given folder:

rmdir('results', 's')

Please note that your results folder will also be removed, so your code would need to create an empty folder again (see mkdir()).

Further, I suggest to always use absolute file paths.

like image 45
braggPeaks Avatar answered Jan 04 '23 08:01

braggPeaks