How to delete only contents from folder? contents might include folders and files

4 次查看(过去 30 天)
Hi
How to delete only contents from folder? contents might include folders and files
Best Vahid

回答(1 个)

Walter Roberson
Walter Roberson 2015-7-28
whichfolder = 'MyFolderName';
dinfo = dir(fullfile(whichfolder,'*.*'));
dinfo(dinfo.isdir) = []; %remove the directories from consideration
for K = 1 : length(dinfo)
thisfile = fullfile(whichfolder, dinfo(K).name);
delete(thisfile);
end

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by