sbt.IO.copyFile / sbt.IO.copyDirectory可执行标志

时间:2014-05-25 17:14:47

标签: scala sbt

当我使用sbt.IO.copyFilesbt.IO.copyDirectory复制文件或文件夹时,文件上的可执行标记将被丢弃。使用sbt帮助函数有没有办法解决这个问题,还是必须使用基本的Java复制函数?

1 个答案:

答案 0 :(得分:1)

使用:

java.nio.file.Files.copy(Path source, Path target, CopyOption... options)

例如,如果您在当前目录中有fromdos:

scala> import java.nio.file._
import java.nio.file._

scala> Files.copy(Paths.get("fromdos"),Paths.get("copyFromDos"),StandardCopyOption.COPY_ATTRIBUTES)
res0: java.nio.file.Path = copyFromDos

有关详细信息,请参阅Java 8Java 7文档。

复制目录

def copyDir(source: Path, dest: Path) {
    Files.copy(source, dest, StandardCopyOption.COPY_ATTRIBUTES)
    if (source.toFile.isDirectory) {
      val dir = source.toFile
      dir.listFiles.foreach(file =>
        copyDir(file.toPath, dest.resolve(file.getName)))
    }
  }