alekhine
alekhine

Reputation: 1620

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.

Upvotes: 5

Views: 5606

Answers (2)

braggPeaks
braggPeaks

Reputation: 1186

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.

Upvotes: 4

Joze
Joze

Reputation: 1305

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

Upvotes: 7

Related Questions