Delete files inside subfolder

40 次查看(过去 30 天)
Hello,
I have a folder:
Testfolder
Inside are:
1.mat
1.txt
1.wav
SubTestfolder
Inside SubTestfolder are:
2.mat
2.txt
2.wav
I do
Del_path = fullfile(TestFolderPath,SubTestFoldername);
delete(Del_path,'*.mat')
I was waiting that 2.mat should be deleted, but it will be 1.mat deleted, not 2.mat. Why? How can I delete files/all files in subfolder?
Thank you!

采纳的回答

Fangjun Jiang
Fangjun Jiang 2020-6-26
use dir('**/*.mat') to find files in subfolders in one shot and then use a for-loop to delete the files.
  1 个评论
Nik Rocky
Nik Rocky 2020-6-26
Thanks, but it is to complicated. I found easy way:
delete(fullfile(SubfolderPath,'*.png')) % or '*'

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by