0
This my code aims to rename a mass of files to set the following pattern: All compound names, words must start in uppercase. First I give a substring for names that have only one word and then I make one while for compound names but does not leave the while, can anyone help me understand why ? I am trying to rename many files.
import java.io.File;
public class App {
    public static void main(String[] args) {
        File diretorio = new File("/home/douglas/roms");
        File[] arquivos = diretorio.listFiles();
        for (File arquivo : arquivos) {
            String nome;
            String extencao = ".gba";
            nome = arquivo.getName();
            nome = nome.toLowerCase();
            nome = nome.substring(0, nome.indexOf(extencao));
            nome = cortarTrecho(nome, " # gba");
            String primeira = nome.substring(0, 1).toUpperCase();
            String restante = nome.substring(1);
            nome = primeira + restante;
            while (nome.contains(" ")) {
                String nomeFinal = "";
                String partes[] = nome.split("\\s+");
                for (int i = 0; i < partes.length; i++) {
                    nomeFinal += "*" + partes[i].substring(0, 1).toUpperCase() + partes[i].substring(1).toLowerCase();
                }
                nomeFinal = nomeFinal.substring(1) + extencao;
                System.out.println(nomeFinal);
            }
        }
    }
    public static String cortarTrecho(String nome, String trecho) {
        int index = nome.indexOf(trecho);
        nome = nome.substring(0, index);
        return nome;
    }
}
You need to see what you want to do, the output condition involves analyzing the variable
nome, as it never changes inside the loop, when it enters, it no longer leaves. It needs to have another condition or change thenomeso that at some point it meets this condition. I don’t even know if I should have thiswhilethere, I have the impression that neither need, should aif, or even that’s necessary. I didn’t write an answer because I don’t even know what to do.– Maniero