Jeff Higgins wrote:
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Collections;
public class ShuffleImages {
public static void main(String[] args) {
ArrayList photos = new ArrayList();
File directory = new File(System.getProperty("user.dir"));
String[] textFileNames = directory.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jpg") || name.endsWith(".JPG");
}
});
for (int i = 0; i < textFileNames.length; i++) {
photos.add(new File(textFileNames[i]));
}
Collections.shuffle(photos);
}
}
thank you very much.. I have incorporated this code into my class to
rename files, it now looks thus, and get no compile or runtime errors, but
it's still not doing it at random, i.e., what I want:
if I have: DSC_0184.JPG, DSC_0185.JPG, DSC_0186.JPG, DSC_0187.JPG,
DSC_0188.JPG, DSC_0189.JPG, DSC_0190.JPG, DSC_0191.JPG, DSC_0192.JPG,
I want, for example: 8th img in this list to be called 1.jpg, 4nd img to
be called 3.jpg, sixth image to be called 10.jpg, etc.. so once they are
renamed they are ordered at random vis-a-vis orig order.. what I have now
after incorporating yr code:
---------------
public class renameRandom {
public static void main(String[] args) {
File directory = new File(System.getProperty("user.dir"));
String[] textFileNames = directory.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jpg") || name.endsWith( ".JPG");
}
});