# Delete content of folders with same name in different subdirectories

I am using Windows 10 and Mathematica 11.3.

I have many same named folders (suppose the name "data") in different subdirectories of a base directory (here "d:\dir").

How can I delete the content (containing only files) of all the folders named "data" without deleting themselves?

E.g. for three folders:

d:\dir\data
filename1
filename2
d:\dir\tmp1\data
filename3
filename4
d:\dir\tmp3\tmp2\data
filename5
filename6
filename7


I would like to delete filename1 to filename7 whereby these names can be anything.

• Does it work for you: Select[FileNames["*/data/*", "d:\\dir", \[Infinity]], Not@*DirectoryQ]? – Kuba Dec 7 '18 at 14:56
• @Kuba: Yes this lists all files in all subdirectories named "data". And now only DeleteFile@ infront and it works. Please post it as an answer? – mrz Dec 7 '18 at 15:29