1
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ Does it work for you: Select[FileNames["*/data/*", "d:\\dir", \[Infinity]], Not@*DirectoryQ]? $\endgroup$ – Kuba Dec 7 '18 at 14:56
  • 1
    $\begingroup$ @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? $\endgroup$ – mrz Dec 7 '18 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.