For loop not in order

Hallo!
I’ve got a lot of confusion because my for loop which searches through folders is giving me this:
45

Yesterday morning all worked and all of the sudden it dont goes in the correct order through the folders… here is my code:

public void fileOrDirectory (String inputFolder, String outputFolder, int level, String fileSuffix){

        File maindir = new File(inputFolder);
        File[] listOfFiles = maindir.listFiles();

        if(analyze==true) {
            // FILE???
            for (int i = 0; i < listOfFiles.length; i++) {

                String filePath = listOfFiles[i].getAbsolutePath();

                if (listOfFiles[i].isFile() && filePath.endsWith(fileSuffix)) {

                    IJ.log(filepath);

                }
            }
        }

        // DIRECTORY???
        for (int i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].isDirectory()) {

                String directoryPath = listOfFiles[i].getAbsolutePath();
                IJ.log(directoryPath);
                fileOrDirectory(directoryPath, outputFolder, level + 1, fileSuffix);

            }
        }
    }

I looked into my history and nothing changed really… did I overlook something?
Thanks for help!!
Anna

Ok got it:
Array.sort(listOfFiles) solide it

2 Likes