How to delete all the contents in a folder using matlab

98 Ansichten (letzte 30 Tage)
ABHAY K K
ABHAY K K am 7 Feb. 2019
Kommentiert: ABHAY K K am 7 Feb. 2019
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!

Akzeptierte Antwort

Stephen23
Stephen23 am 7 Feb. 2019
Bearbeitet: Stephen23 am 7 Feb. 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."

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by