/************************************************************************************
C++ Std格式的比较函数,用来实现两个带有干扰字符的字符串的大小比较。
实现上采用在字符串中剔除对应的后缀干扰字符,只对关注部分进行比较
比如10.jpg , 111.jpg,该函数返回10.jpg < 111.jpg
************************************************************************************/
bool StringCompareFunc(string a , string b)
{
	char ca[32] , cb[32];
	ZeroMemory(ca , sizeof(char) * 32);
	ZeroMemory(cb , sizeof(char) * 32);
	a._Copy_s(ca , 32 , a.length() - 4);
	b._Copy_s(cb , 32 , b.length() - 4);

	return atoi(ca) < atoi(cb);
}
Example #2
0
HRESULT ScanDir(string strFind)
{
    HANDLE hFind;
    WIN32_FIND_DATA wfd;
    LPSTR lpPath = new char[MAX_PATH];
    LPWSTR lpPathW = new wchar_t[MAX_PATH];
    LPSTR lpFileName = new char[MAX_PATH];
    LPWSTR lpFileNameW = new wchar_t[MAX_PATH];
    string sFileName;
    strFind += "\\*";
    strFind._Copy_s(lpPath, strFind.length(),strFind.length());
    lpPath[strFind.length()]='\0';
    ::MultiByteToWideChar( CP_ACP, NULL,lpPath, -1, lpPathW, MAX_PATH);
    hFind = FindFirstFile( lpPath, &wfd );
    int nIndex = 0;
    if(INVALID_HANDLE_VALUE == hFind)
    {
        debugLog("Invalid handle type - Directory most likely empty");
        debugLog(lpPath);
        debugLog(lpFileName);
    }
    else
    {
        nIndex = 0;
        do
        {
            sFileName = wfd.cFileName;
            sFileName._Copy_s(lpFileName, sFileName.length(), sFileName.length());
            lpFileName[sFileName.length()]='\0';
            ::MultiByteToWideChar( CP_ACP, NULL,lpFileName, -1, lpFileNameW, MAX_PATH);
            if(FILE_ATTRIBUTE_DIRECTORY == wfd.dwFileAttributes)
            {
                string nextDir;
                nextDir += lpPath;
                string nextDir1;
                nextDir1 += lpFileName;
                nextDir.erase(nextDir.size() - 1, 1);
                nextDir += nextDir1;
                ScanDir(nextDir);
            }
            else
            {
                string filePath;
                string filePathX;
                string fileNameX;
                filePath += lpPath;
                string fileName;
                fileName += lpFileName;
                filePath.erase(filePath.size() - 1, 1);
                filePathX += filePath;
                fileNameX += fileName;
                filePath += fileName;
                LPSTR FileA = new char[MAX_PATH];
                LPSTR FileNameA = new char[MAX_PATH];
                LPSTR FilePathA = new char[MAX_PATH];
                filePathX._Copy_s(FilePathA, filePathX.length(),filePathX.length());
                fileNameX._Copy_s(FileNameA , fileNameX.length(),fileNameX.length());
                filePath._Copy_s(FileA, filePath.length(),filePath.length());
                FileA[filePath.length()]='\0';
                LPWSTR FileB = new wchar_t[MAX_PATH];
                ::MultiByteToWideChar(CP_ACP, NULL, FileA, -1, FileB, MAX_PATH);
                if (isNXE(FileB,filePathX))
                {
                    NXE temp(fileNameX,filePathX);
                    allNXE.push_back(temp);
                }
            }
            nIndex++;
        }
        while(FindNextFile(hFind, &wfd));
        FindClose(hFind);
    }
    return S_OK;
}