As it seems to me, you need to dig in the direction of the function findfirst () and checking the string from the name by pattern . followed by sorting and rewriting to another directory.
Well, as an option, write a shell script and run it from the application.
UPD: here is a bit of code in which the search takes place; you only need to change a little (make a copy)
#include <iostream> #include <Windows.h> using namespace std; int main(){ WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; // Find the first file in the directory. hFind = FindFirstFile("C:\\*.bin", &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { printf ("Invalid file handle. Error is %u.\n", GetLastError()); } else { printf ("First file name is %s.\n", FindFileData.cFileName); // List all the other files in the directory. while (FindNextFile(hFind, &FindFileData) != 0){ printf ("Next file name is %s.\n", FindFileData.cFileName); } FindClose(hFind); } return 0; }