Created
October 31, 2013 17:01
-
-
Save pvorb/7253230 to your computer and use it in GitHub Desktop.
Copies all MP3-files in a directory to another directory in a random order.
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.io.File | |
import java.nio.file.{ Files, StandardCopyOption } | |
import java.util.{ Collections, Random } | |
import scala.collection.JavaConversions | |
object RandomCopy extends App { | |
val src = new File("""E:\Backup\Auto""") | |
val dest = new File("""F:\""") | |
val files = | |
JavaConversions.mutableSeqAsJavaList(src.listFiles().filter(_.getName().endsWith(".mp3"))) | |
val seed = System.nanoTime | |
Collections.shuffle(files, new Random(seed)) | |
var i = 1 | |
val fs = JavaConversions.iterableAsScalaIterable(files) | |
for (f <- fs) { | |
val newPath = new File(dest, f.getName).toPath | |
Files.copy(f.toPath, newPath, StandardCopyOption.REPLACE_EXISTING) | |
println(i + "/" + fs.size + ", " + f.getName) | |
i += 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment