Skip to content

Instantly share code, notes, and snippets.

@ashugupt
Created July 24, 2015 15:02
Show Gist options
  • Save ashugupt/f88e30b6ce23f5445571 to your computer and use it in GitHub Desktop.
Save ashugupt/f88e30b6ce23f5445571 to your computer and use it in GitHub Desktop.
Copies files from one directory tree to output
import java.nio.file.{DirectoryStream, Files, Path, Paths}
import scala.collection.JavaConverters._
import scala.collection.mutable.ArrayBuffer
val filesList = ArrayBuffer[String]()
var directoryStream =
Files.newDirectoryStream(Paths.get("/Users/ashugupt/Pictures/chandrataal"))
val outputJpegPath = Paths.get("/Users/ashugupt/Pictures/chandrataal/jpegs")
val outputRawPath = Paths.get("/Users/ashugupt/Pictures/chandrataal/raw")
def copy(stream: DirectoryStream[Path]): Unit = {
for (path <- stream.asScala.toList) {
if (Files.isDirectory(path)
&& !path.endsWith(Paths.get(".DS_Store"))
&& !Files.isSameFile(path, outputJpegPath)
&& !Files.isSameFile(path, outputRawPath)
) {
copy(Files.newDirectoryStream(path))
} else if (!Files.isDirectory(path)
&& !path.endsWith(Paths.get(".DS_Store"))
&& !Files.isSameFile(path, outputJpegPath)
&& !Files.isSameFile(path, outputRawPath)
) {
println(path.getFileName)
if (path.toString.toUpperCase.endsWith("JPG")) {
Files.copy(path, Paths.get(outputJpegPath.toString + "/" + +System.currentTimeMillis + "-" + path.getFileName))
} else if(path.toString.toUpperCase.endsWith("NEF")) {
Files.copy(path, Paths.get(outputRawPath.toString + "/" + +System.currentTimeMillis + "-" + path.getFileName))
}
}
}
}
copy(directoryStream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment