How to delete all the contents in a folder using matlab

95 ビュー (過去 30 日間)
ABHAY K K
ABHAY K K 2019 年 2 月 7 日
コメント済み: ABHAY K K 2019 年 2 月 7 日
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."
  1 件のコメント
ABHAY K K
ABHAY K K 2019 年 2 月 7 日
Thanks a lot Stephen Cobeldick. the code is working.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by