I have a linux operating system, by the way.
import java.io.*;
import java.text.DecimalFormat;
import java.awt.Desktop;
public class rename {
public static boolean renameTo(File Pictures){
File[] listofFiles = Pictures.listFiles();
boolean check = false;
if(listofFiles != null){
int count = 000;
for(File pic : listofFiles){
String filename = pic.getName();
String extention = filename.substring(filename.lastIndexOf(".")+1, filename.length());
String pictureExtention = "JPG";
if(extention.equals(pictureExtention)){
count++;
pic.renameTo(new File((new DecimalFormat("000").format(count))+".JPG"));
check=true;
}
}
}
return check;
}
public static void main(String[] args) throws IOException {
String homePath = System.getProperty("user.home");
File home = new File(homePath);
File pictures = new File(home, "Test");
Desktop.getDesktop().open(pictures);
boolean x = renameTo(pictures);
System.out.println(x);
}
}
Therefore, by renaming many JPG files, it will delete some from the file, and I cannot understand why. Any ideas? I want him to rename the file 001.JPG (say 25 images) 025.JPG. However, it correctly renames those that are not deleted.
source
share