How to delete all the contents in a folder using matlab
97 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone, I had a small doubt how to clear all the contents of the folder 'C:\Project\Template\Simulation\Models' which is saved to a variable. i am using this in my code for which the deletion is not happening.
function filetransfer(Vehicleline,Select_model,Select_KW)
root_src = 'C:\Project';
root_dest = 'C:\Project\Template\Simulation\Models';
root_vehicleline = strcat(root_src,'\',Vehicleline,'\','Models');
root_src_model = strcat(root_vehicleline,'\',Select_model,'\',Select_KW);
locals = dir('C:\Project\Template\Simulation\Models');
if ~isempty(root_dest)
rmdir(root_dest)
copyfile(root_src_model,root_dest);
else
copyfile(root_src_model,root_dest);
end
end
Thanks in advance!
0 commentaires
Réponse acceptée
Stephen23
le 7 Fév 2019
Modifié(e) : Stephen23
le 7 Fév 2019
Use
rmdir(root_dest,'s')
% ^^^ you need this
to also delete all of the folder contents. This is explained in the rmdir documentation, which states that for the syntax you used " folderName must be empty.", but for the syntax that I showed you "rmdir folderName s also attempts to remove all subfolders and files in folderName, regardless of their write permissions."
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!