Effacer les filtres
Effacer les filtres

How can I delete files within subfolders?

8 vues (au cours des 30 derniers jours)
caroline Figueroa
caroline Figueroa le 14 Sep 2016
Modifié(e) : Stalin Samuel le 14 Sep 2016
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!

Réponses (1)

Stalin Samuel
Stalin Samuel le 14 Sep 2016
Modifié(e) : Stalin Samuel le 14 Sep 2016
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

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by