Created
July 24, 2015 15:02
-
-
Save ashugupt/f88e30b6ce23f5445571 to your computer and use it in GitHub Desktop.
Copies files from one directory tree to output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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