How to delete all the contents in a folder using matlab

97 次查看(过去 30 天)
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!

采纳的回答

Stephen23
Stephen23 2019-2-7
编辑:Stephen23 2019-2-7
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."

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by