为什么 readdirSync 会自动对结果进行排序?

Why does readdirSync sort the results automatically?

我使用 fs.readdirSync(path) 方法检索数组中的文件名。为什么结果数组中的文件名要排序?

function checkFile() {
    try {
        let imgsFolder = './images/';
        let imgs = fs.readdirSync(imgsFolder);

        fs.statSync(imgsFolder);
        return imgs;
    }

    catch (e) {
        console.log("Folder does not exist.");
        fs.mkdirSync("images/");
        console.log("Folder was created.");
    }
}

checkFile();

例如,文件夹中有以下文件:tts.jpg, array.jpg, man.jpg,但我将它们检索为 array.jpg, man.jpg, tts.jpg

好吧,如果你阅读了 readdir information that is referenced by the readdirSync 方法,就会出现以下评论

The order in which filenames are read by successive calls to readdir() depends on the filesystem implementation; it is unlikely that the names will be sorted in any fashion.