void CUpdialog::DeleteTree(CFtpConnection *objConn, CString strSour)
{
    
    CStringArray   dirList; 
    CFtpFileFind   ftpFind(objConn); 
    BOOL filebool;
    char szWildCard[MAX_PATH] = {0};
    CString Newfiname,str;
    sprintf(szWildCard, "/%s/*", strSour);
    str.Format("%s",szWildCard); //           //88888/777//*
    if (str.Right(2)=="/*" && str.Left(2)=="//" )
   {
     str.Replace("//", "/" );   }
   ConvertGBKToUtf8(str);    
   BOOL   bContinue   =   ftpFind.FindFile(str); 
   if   (!bContinue) 
    { 
ftpFind.Close(); 
return; 
    } 
BOOL   bDir   =   FALSE; 
CString   strFileName,   strFilePath; 
while   (bContinue) 

bContinue   =   ftpFind.FindNextFile(); 
strFileName   =   ftpFind.GetFileName(); 
strFilePath   =   ftpFind.GetFilePath(); 
theApp.ConvertUtf8ToGBK(strFileName);
theApp.ConvertUtf8ToGBK(strFilePath);
filebool = ftpFind.IsDirectory();
char szFullName[MAX_PATH];
if (strFilePath.Right(1)=="." ||strFilePath.Right(2)=="..")
{
continue;
}

if (filebool) //判断目录 如果结尾有有/ 则不加 否则加上
{
// 目录递归调用RemoveDir
            if (strFilePath.Right(1)!="/" || strFilePath.Right(1)!="\\")

{
Newfiname.Format("%s/",strFilePath);
            }
            else{ 
Newfiname = strFilePath;
}
dirList.Add(Newfiname);  }
else
{
// 文件直接删除
ConvertGBKToUtf8(strFilePath);
objConn->Remove(strFilePath);//     /88888/qr/2.mp3

        }
}  //
ftpFind.Close(); 
int aa = strFilePath.ReverseFind('/');   //  /88888/qwe/2.txt
CString name = strFilePath.Left(aa);
ConvertGBKToUtf8(name); 
  objConn->RemoveDirectory(name); int   count=dirList.GetSize(); 
for(int   i=0;i <count;i++) 

DeleteTree(objConn,Newfiname);

int aa1 = Newfiname.ReverseFind('/');   //  /88888/qwe/2.txt
CString name1 = strFilePath.Left(aa1);
ConvertGBKToUtf8(name1); 
objConn->RemoveDirectory(name1);
dirList.RemoveAll(); }
请大家帮忙看看代码  
本段代码是删除FTP文件及其内容
代码中 strFilePath   =   ftpFind.GetFilePath(); 
问题 是如果是英文或者是数字的目录 可以正确使用得到正确路径 程序正确运行
但是如果是中文的话得不到正确路径。
请大家见过这样的问题的 给予帮助

解决方案 »

  1.   


    从上面的代码上看自然不是Unicode编码的使用Unicode编码规范
      

  2.   

    好像是字符编码的问题,使用多字节和UNICODE必须一致
      

  3.   

    Unicode和多字符对于中文的宽度不一样,改成统一unicode就可以啦就是字符串前面加上_T("");就可以
      

  4.   

    传入参数要么是unicode的,要么是acp的,不要是utf-8的。
    可以用int size=WideCharToMultiByte(CP_ACP,0,(LPWSTR)str,-1,NULL,0,NULL,NULL);
    m_pNewMem = new char[size];
    memset(m_pNewMem, 0, size);
    WideCharToMultiByte(CP_ACP,0,(LPWSTR)str,-1,m_pNewMem,size,NULL,NULL);
      

  5.   

    是的Unicode的话,
    vConvertGBKToUtf8(str);//--------------去掉这一行
    BOOL bContinue = ftpFind.FindFile(str);
      

  6.   


    void DeleteTree(CFtpConnection *objConn, CString strSour)
    {    CStringArray dirList;  
        CFtpFileFind ftpFind(objConn);  
        BOOL filebool;
        char szWildCard[MAX_PATH] = {0};
        CString Newfiname,str;
        sprintf(szWildCard, _T("/%s/*"), strSour);
        str.Format("%s",szWildCard); // //88888/777//*
        if (str.Right(2) == _T("/*") && str.Left(2)== _T("//") )
        {
            str.Replace(_T("//"), _T("/") );
        }
        ConvertGBKToUtf8(str);   
        BOOL bContinue = ftpFind.FindFile(str);  
        if (!bContinue)  
        {  
            ftpFind.Close();  
            return;  
        }  
        BOOL bDir = FALSE;  
        CString strFileName, strFilePath;  
        while (bContinue)  
        {  
            bContinue = ftpFind.FindNextFile();  
            strFileName = ftpFind.GetFileName();  
            strFilePath = ftpFind.GetFilePath();  
            theApp.ConvertUtf8ToGBK(strFileName);
            theApp.ConvertUtf8ToGBK(strFilePath);
            filebool = ftpFind.IsDirectory();
            char szFullName[MAX_PATH];
            if (strFilePath.Right(1)== _T(".") ||strFilePath.Right(2)== _T(".."))
            {
                continue;
            }        if (filebool) //判断目录 如果结尾有有/ 则不加 否则加上
            {
                // 目录递归调用RemoveDir
                if (strFilePath.Right(1)!=_T("/") || strFilePath.Right(1)!=_T("\\"))            {
                    Newfiname.Format(_T("%s/"),strFilePath);
                }
                else{  
                    Newfiname = strFilePath;
                }
                dirList.Add(Newfiname);          }
            else
            {
                // 文件直接删除
                ConvertGBKToUtf8(strFilePath);
                objConn->Remove(strFilePath);// /88888/qr/2.mp3        }
        } //
        ftpFind.Close();  
        int aa = strFilePath.ReverseFind('/'); // /88888/qwe/2.txt
        CString name = strFilePath.Left(aa);
        ConvertGBKToUtf8(name);  
        objConn->RemoveDirectory(name);    int count=dirList.GetSize();  
        for(int i=0;i <count;i++)  
        {  
            DeleteTree(objConn,Newfiname);
        }  
        int aa1 = Newfiname.ReverseFind('/'); // /88888/qwe/2.txt
        CString name1 = strFilePath.Left(aa1);
        ConvertGBKToUtf8(name1);  
        objConn->RemoveDirectory(name1);
        dirList.RemoveAll();  }
    还需要把你的工程选择Unicode编码才行