Click here to Skip to main content
15,914,221 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Im trying to upload a directory and all the files in it to a server using wininet.

here is my code

C++
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...
Posted
Updated 23-Jul-13 14:20pm
v5
Comments
pasztorpisti 23-Jul-13 19:21pm    
I wouldn't filter for the archive flag, treat everything as file that is not a directory. Inserting a few log statements would be very useful besides debugging. Log out every strings before and after modification. Log out every errors. And so on... Such a function usually have bugs like missing '\\' characters...
[no name] 23-Jul-13 22:06pm    
This is a big ask as you have not mentioned anything about what the problem is.
[no name] 23-Jul-13 22:05pm    
Agreed - I think this critter can only be debugged in situ. Things like is it finding directory etc etc.

1 solution

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;

C++
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 ) );
}


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

Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900