Skip to content

Instantly share code, notes, and snippets.

@pvorb
Created October 31, 2013 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvorb/7253230 to your computer and use it in GitHub Desktop.
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.
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