• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 877
  • Last Modified:

How to copy entire folder structure from C++?

Is there a Windows API function that will copy an entire folder structure?  I am particularly interested in a solution that doesn't abort if one of the files can't be copied because of a sharing vilation.

Only an answer that will give me the above solution will be accepted.  If there's no way to do this via a Windows API call, then a code snippet will be accepted, otherwise the answer will be rejected.
1 Solution

There is no Windows API. What you can do is for a folder repetedly call FindFirstFile/FindNextFile and copy the files (with CopyFile), and when a directory is found, call the same function recursively.

I cannot give you a code snippet right now because I don't remember the parameters to all those APIs, but if you are interested, I can look them up in help and write those functions for you. I work in C/C++, so if you work in another language, I could write a simple DLL for you.

Anyway, send me an e-mail to luisr@iname.com if you are interested.

How about using the DOS command xcopy with the /s option?
You can fire it off from your c++ code using the CreateProcess API.
Hmm - this can be done much easier, 'SHFileOperation()' should do the job...
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

shrifAuthor Commented:
I'm not aware of a single API that will solve your problem but here is a
propose solution

int CopyFiles(char *szFromDir, char *szToDir)
      long hFile;
      struct _finddata_t fd;
      char szBuffer[256];

      sprintf(szBuffer,"%s\\*.*", szFromDir);
      if( (hFile = _findfirst(szBuffer, &fd)) == -1L ) return(-1);

            char szFrom[256],szTo[256];
            if(*fd.name !='.')

                  //check for subdirectories

                  //check for volume space remaining
                  CFileStatus status;
                  CFile::GetStatus(szFileName, status );
                  if(status.m_attribute==      0x10) //directory

    }while(_findnext(hFile, &fd) == 0);
    _findclose( hFile );


shrifAuthor Commented:
jkr, repost as an 'answer'

Thanx shrif ;-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now