指定されたフォルダの下で指定されたフォーマットのファイルをC++とMFCで巡回


最近、仕事中にファイルを読み書きする必要がある操作は、単一モジュールとVCインタフェースに対して2つの異なる操作方法があり、他にもよく研究されていないので、ここで記録します.
先着コード
//c++  
    _finddata_t file;
    int k;
    long HANDLE;
    string strFloderPath = "        ";
    string strString = strFloderPath + "\\*.*";
    const char* str1 = strString.c_str();

    k = HANDLE = _findfirst(str1, &file);
    while (k != -1)
    {
        string strTemp = file.name;
        if (strTemp != "." && strTemp != "..")
        {
            int maxChar = strTemp.length();
            string rightFour = strTemp.substr(maxChar - 4, 4);
            if (".xxx" == rightFour)//       
            {
                string strFilePath = strFloderPath + file.name;//  
                DoSomething(strFilePath);//          
            }
        }
        k = _findnext(HANDLE, &file);
    }
    _findclose(HANDLE);

//中間の関数はMSDNを調べることができ、ヘッダファイルは含む必要がある
//MFC  
    CString fdPath;
    CString strDataPath = strFloderPath + "\\*.*";
    CString strTmp;

    CFileFind find;//MFC      
    BOOL bf = find.FindFile(strDataPath);
    while (bf)//           
    {
        bf = find.FindNextFile();
        if (!find.IsDots())
        {
            fdPath = find.GetFilePath();
            strTmp = fdPath.Right(4);//CString   
            strTmp.MakeLower();
            if (".xxx" == strTmp)//      
            {
                DoSomething(fdPath);//       
            }
        }
    }
    find.Close();

MFCでは多くの一般的な操作を二次パッケージ化しており、関数機能がそろっており、インタフェースにファイル操作用MFCが含まれている場合は便利です.C++のバージョンは、単一モジュールで使用されるファイル操作に適用され、外部のMFCライブラリを必要としないパッケージ化されます.