I cleaned up the file sorting code so that files should now be reliably sorted, and files in a directory will always be sorted before any subdirectories.