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!
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!