2012-04-24 72 views
0

鑑於下面的代碼,我需要它在韓文/日文Windows SO上工作。 它只是沒有工作,我不能告訴你爲什麼...Windows搜索C++(MFC)CFindFiles路徑分隔符

可能你們幫我嗎?

void RecurseSearch(LPCTSTR pstr, CString serchTerm, CSimpleMap<CString,CString>* arr) 
{ 
    CFileFind finder; 
    // build a string with wildcards 
    CString strWildcard; 
    int code_point = 0x5c ; 
    WCHAR chr = (WCHAR) code_point; 
    strWildcard.Format(_T("%s%c*%s*"), pstr,chr,serchTerm); 
    CString actualFolder; 
    // start working for files 
    BOOL bWorking = finder.FindFile(strWildcard); 

    while (bWorking) 
    { 

     bWorking = finder.FindNextFile(); 
     actualFolder=finder.GetFilePath(); 
     // skip . and .. files; otherwise, we'd 
     // recur infinitely! 

     if (finder.IsDots()) 
      continue; 

     // if it's a directory, recursively search it 

     else if (finder.IsDirectory()) 
     { 
      CString str = finder.GetFilePath(); 
      RecurseSearch(str, serchTerm, arr); 
     } 
     else 
     { 
      if(arr->GetSize()>200) return; 
      if(arr->FindKey(finder.GetFileURL())==-1) 
       arr->Add(finder.GetFileURL(),finder.GetFileURL()); 
     } 
    } 
    bWorking = finder.FindFile(pstr+(CString)chr+(CString)_T("*")); 
    while(bWorking) 
    { 
     bWorking = finder.FindNextFile(); 
     actualFolder =finder.GetFilePath(); 
     if (!finder.IsDirectory() || finder.IsDots()) continue; 
     else 
     { 
      RecurseSearch(actualFolder, serchTerm, arr); 
     } 

    } 
    finder.Close(); 
} 

此代碼的工作在美國的Windows就好了,但沒有做韓國... 我連路徑分隔符設置爲正確的Unicode,但沒有...

編輯:我我們發現了錯誤,它與ItemNames和ItemDisplayNames有關。我需要搜索ItemDisplayNames,但是搜索ItemName的CFindFile。

我更改代碼以使用ISearchFolderItemFactory,然後執行AQS查詢。

無論如何,TY老闆!

回答

1

對路徑分隔符使用反斜線。不管當前的語言如何,反斜槓都被記錄爲在所有情況下都被接受。它可能是MFC正在搞砸東西...

這裏有兩個鏈接,應該有所幫助。

http://msdn.microsoft.com/en-us/library/dd317748(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#naming_conventions

+1

NOP!不起作用!我已經測試過'/''\'''''₩'似乎沒有做到這一點! – 2012-04-24 21:30:33

+0

@Carlos_rpg:奇怪。什麼版本的MFC?在韓文版中,'₩'的字符值是多少。例如:'printf(「0x%X \ n」,'₩');' - 根據MSFT,路徑sep在所有情況下應該是0x5C,並且只顯示爲不同的字符。至少這是我閱讀它的方式。 – JimR 2012-04-24 21:47:30