Reputation: 940
Suppose I have a Scala program that creates files ending in .foo
.
I'm building with sbt
and want to remove these files whenever sbt clean
is called.
Add additional directory to clean task in SBT build shows that a singe file can be added by
cleanFiles <+= baseDirectory { _ / "test.foo" }
However, it's unclear how to extend this to do:
cleanFiles <append> <*.foo>
All .foo
files will be in the same directory, so I don't need to recursively check directories.
Though, that would also be interesting to see.
sbt
to clean files matching a wildcard, or regex?sbt clean
remove files my program generates?
Should I instead use a flag in my program? Using sbt clean
seems cleaner to me rather
than having to call sbt clean
then sbt "run --clean"
.Upvotes: 3
Views: 1386
Reputation: 10657
This will find anything that matches *.foo
in the base directory (but not child directories):
cleanFiles <++= baseDirectory (_ * "*.foo" get)
This works because Seq[File]
gets implicitly converted to a PathFinder
, which has methods such as *
(match the pattern in the base directory) and **
(match the pattern including child directories). Then get
converts it back to a Seq[File]
.
Upvotes: 5