How to clear contents of a directory without deleting the directory?

I’m attempting to add the contents of a “generated” folder to my clean task, but it deletes the “generated” folder itself, which is a problem because the compile depends on the folder being there.

Is there a way to simply delete the contents of the directory, either by defining a task or by adding them to cleanFiles ?

Hi @PeeDub, moved this question to Tooling category since it is way more related to sbt than Play itself.

Well, given that, I don’t know if sbt has its shortcuts to do this, but you can have something like:

cleanFiles ++= sbt.Path.allSubpaths(baseDirectory.value / "logs").map(_._1).toSeq

The scaladoc for allSubpaths says:

 * Selects all descendants of `base` directory and maps them to a path relative to `base`.
 * `base` itself is not included.

So I think it is what you want. :slight_smile:


Having a little difficulty with the “map(_._1)” portion of that line. I’m looking to include all files in all the base directories, but can’t seem to come up with the proper syntax. A little help please?

What do you mean? Do you see an error?

Could you better explain this? Do you mean multiple subprojects directories? How is your project structured?