递归c ++ wininet [英] Recursion c++ wininet

查看:132
本文介绍了递归c ++ wininet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用wininet将目录及其中的所有文件上传到服务器。



这是我的代码



Im trying to upload a directory and all the files in it to a server using wininet.

here is my code

BOOL CListfilesDlg::recursion(CString sPath) // sPath is the folder name
{
    HANDLE hFind;
    WIN32_FIND_DATA fdFind;
    UpdateData(true);

    CString StrPathS = m_editvalue; //m_editvalue has the full path of the folder im viewing in a listcontrol

    CString salvation =  StrPathS + sPath;
    UpdateData(false);

    CString ren = salvation + "*.*";
    hFind = FindFirstFile( ren, &fdFind );

    do
    {
        if( fdFind.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
        {

if(IsDots(fdFind.cFileName)) continue;
            FtpCreateDirectory(hIConnect,fdFind.cFileName);
            UpdateData(true);
            CString cov = sPath;
            CString fire = m_editvalue;
            UpdateData(false);
            CString newPath =  fire + cov + "\\" + fdFind.cFileName;
            recursion(newPath);
        }
        if(fdFind.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE)
            continue;
        else
        {
        }
    }
    while( FindNextFile( hFind, &fdFind ) );

    return recursion(sPath);
}





有人可以修复代码吗?我试着调试没有运气...



Can someone fix the code? I tried debugging with no luck...

推荐答案

你不应该在你的内部重复使用像 m_editvalue 这样的全局像这样的递归函数,它会构建错误的字符串。相反,在调用函数时尝试传递 m_editvalue 的值,然后让函数根据输入而不是周围类的成员创建新路径。 />


这样的东西可能适合你;



you shouldn't reuse a global like m_editvalue inside your recursive function like that, it will build up the wrong string. Instead, try to pass in the value of m_editvalue when calling the function and then have the function create new paths based on the input rather than the members of the surrounding class.

Something like this might work for you;

void CListfilesDlg::recursion(CString sPath)
{
  HANDLE hFind;
  WIN32_FIND_DATA fdFind;
    
  UpdateData(true);
 
  CString ren = sPath + "\\*.*";
  hFind = FindFirstFile( ren, &fdFind );
 
  do
  {
    if( fdFind.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
    {
      if(IsDots(fdFind.cFileName)) 
        continue;
            
      FtpCreateDirectory(hIConnect,fdFind.cFileName);
 
      // I left these calls in, I don't know how relevant they are
      // after my changes           
      UpdateData(true);
      UpdateData(false);
            
      CString newPath = sPath + "\\" + fdFind.cFileName;
      recursion(newPath);
    }

    if(fdFind.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE)
      continue;
  }
  while(FindNextFile( hFind, &fdFind ) );
}





像这样调用函数; 递归(m_editvalue); 它应该可以工作。



希望这会有所帮助,

Fredrik



Call the function like this; recursion(m_editvalue); and it should work.

Hope this helps,
Fredrik


这篇关于递归c ++ wininet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆