I know these three sorting have some differences, but I still think we can at least refactor the code here to a function as follows and share it here and the other one below.

How about moving your code here to a local function
````
    function _filenameSort(file1, file2) {
        var name1 = file1.name,
            name2 = file2.name;
        if (brackets.platform === "win") {
            name1 = FileUtils.getFilenameAndExtension(file1.name).name;
            name2 = FileUtils.getFilenameAndExtension(file2.name).name;
        }
        return name1.toLocaleLowerCase().localeCompare(name2.toLocaleLowerCase());
    }
````

And then replace the anonymous function here with ``_filenameSort``