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.
system('rm -rf results/*')
should be exactly the same as your C code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With