I had to walk alone on the sand,
and I had to walk forever
- Davey
"
import java.io.*;
import java.util.*;
/**
* Quick class to copy files from one directory to another, giving the new
* copies a random name along the way.
*/
public class Cop {
public static void main(String []args) throws IOException {
File in = new File(args[0]);
File out = new File(args[1]);
if (!out.isDirectory()) {
System.err.println("destination must be a directory");
System.exit(1);
}
Random rand = new Random(System.currentTimeMillis());
File []files = in.listFiles();
for (int i = 0; i < files.length; i++) {
File f = files[i];
if (f.isDirectory()) {
continue;
}
String []parts = f.getName().split("\\.");
String suffix = parts[parts.length - 1];
String name = rand.nextLong() + "." + suffix;
File nf = new File(out, name);
while (nf.exists()) {
name = rand.nextLong() + "p." + f.getName();
nf = new File(out, name);
}
InputStream ins = new FileInputStream(f);
OutputStream outs = new FileOutputStream(nf);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = ins.read(buf)) > 0) {
outs.write(buf, 0, len);
}
System.out.println(f);
}
}
}
david.petersheim@gmail.com
pics