Help with moving jpeg files
Code:
import com.sun.image.codec.jpeg.*;
import java.awt.Image;
import java.io.*;
import java.util.*;
public class Sortimages {
public static void main(String[] args) throws Exception {
File images = new File("H:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\Wallpapers\\Unidentified");
File[] files = images.listFiles();
File newfile;
Image image;
for (int i = 0; i < files.length; i++) {
image = JPEGCodec.createJPEGDecoder(new FileInputStream(files[i])).decodeAsBufferedImage();
int width = image.getWidth(null);
int height = image.getHeight(null);
File folder = new File("H:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\Wallpapers\\" + width + "x" + height + "\\");
folder.mkdir();
if ((i + 1) < 10) {
newfile = new File(folder, "Picture - 00" + (i + 1) + ".jpg");
} else if ((i + 1) < 100) {
newfile = new File(folder, "Picture - 0" + (i + 1) + ".jpg");
} else {
newfile = new File(folder, "Picture - " + (i + 1) + ".jpg");
}
files[i].renameTo(newfile);
}
}
}
My main purpose with this program is to move all my jpeg files to different folders depending on it's resolution, for example, if a certain file has 1920x1200 in resolution, then that file should be moved to the folder called 1920x1200. and so on. However, when running the file, the folders are createn but no files are moved.
Can anyone see what I'm doing wrong?