diff --git a/extendedcommands.c b/extendedcommands.c index 29adf56..c79836e 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -214,6 +214,21 @@ char** gather_files(const char* directory, const char* fileExtensionOrDirectory, return NULL; } + // sort the result + if (files != NULL) { + for (i = 0; i < total; i++) { + int curMax = -1; + int j; + for (j = 0; j < total - i; j++) { + if (curMax == -1 || strcmp(files[curMax], files[j]) < 0) + curMax = j; + } + char* temp = files[curMax]; + files[curMax] = files[total - i - 1]; + files[total - i - 1] = temp; + } + } + return files; }