How can I delete files within subfolders?

6 ビュー (過去 30 日間)
caroline Figueroa
caroline Figueroa 2016 年 9 月 14 日
編集済み: Stalin Samuel 2016 年 9 月 14 日
Hi matlab users,
I would like to delete specific files within subfolders in my directory. I have about a 100 subject folders in one directory (subj 01001, 01002 etc). I would like to remove only the .nii files within a subfolder 'rest', which is in all the subject's folders. So far I have figured out how to do this for 1 subject at a time. I was wondering if there is a way to remove the .nii files within al the subfolders of the subjects at once? This what I am using for one subject: delete('/data/caroline/01001/rest/*.nii")
Does anyone have a script for this?
Thank you in advance!

回答 (1 件)

Stalin Samuel
Stalin Samuel 2016 年 9 月 14 日
編集済み: Stalin Samuel 2016 年 9 月 14 日
get the list of all the sub folders in a variable ,For example variable 'a'
Then delete the files using below command
for it=1:n %n is the length of the folder list
delete(sprintf('/data/caroline/01001/%s/*.nii"',a{it}))
end

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by