question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a recursive sbt.IO.listFiles

See original GitHub issue

As of SBT 0.13.7, there doesn’t appear to be a way to recursively list files in a directory using the provided sbt.IO.listFiles helper functions. Essentially I want an sbt.IO.listFiles that lists all files within a given directory, and optionally all of its subdirectories.

http://www.scala-sbt.org/0.13.7/api/index.html#sbt.IO$

When needed, I end up doing something like this peppered around several build definitions:

def listFilesRecursively(dir: File): Seq[File] = {
  val list = sbt.IO.listFiles(dir)
  list.filter(_.isFile) ++ list.filter(_.isDirectory).flatMap(listFilesRecursively)
}

It would be great if SBT could fold this into sbt.IO — either by creating a new function named listFilesRecursively, or add an optional recursive:Boolean = false argument to the existing sbt.IO.listFiles functions which one could set to true to make them recursive as needed.

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
reactormonkcommented, Jun 17, 2016

Just in case anyone comes across this, Path.allSubpaths

2reactions
eed3si9ncommented, Dec 29, 2014

sbt also has Paths, which is pretty versatile. What you’re after could be written as:

scala> import sbt._, Path._
import sbt._
import Path._

scala> val base = new java.io.File(".")
base: java.io.File = .

scala> ((base ** "*") filter { !_.isDirectory }).get
res0: Seq[java.io.File] = ArrayBuffer(./.gitattributes,...

or more concisely as:

scala> (base ** (-DirectoryFilter)).get
res1: Seq[java.io.File] = ArrayBuffer(./.gitattributes,...
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I list all files in a subdirectory in scala? - Stack Overflow
os-lib is the easiest way to recursively list files in Scala. os.walk(os.
Read more >
IO - SBT
Deletes each file or directory in files recursively.
Read more >
How to list files in a directory in Scala (and filter the list)
Using Scala, you want to get a list of files that are in a directory, potentially limiting the list of files with a...
Read more >
Java File IO - List files and directories recursively - CodeJava.net
Java File IO - List files and directories recursively · If the file is a directory: Print out directory name. Repeat the step...
Read more >
IO - sbt.io.IO - javadoc.io
def append(file: File, content: String, charset: Charset ... Deletes each file or directory (recursively) in files . ... def listFiles(filter: java.io.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found