Solved

How to copy entire folder structure from C++?

Posted on 1999-01-19
7
860 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:shrif
7 Comments
 
LVL 3

Expert Comment

by:luisr
Comment Utility

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.

0
 
LVL 2

Expert Comment

by:rayb
Comment Utility
How about using the DOS command xcopy with the /s option?
You can fire it off from your c++ code using the CreateProcess API.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Hmm - this can be done much easier, 'SHFileOperation()' should do the job...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:shrif
Comment Utility
thanks.
0
 

Expert Comment

by:ramrocket
Comment Utility
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);

      do
          {
            char szFrom[256],szTo[256];
            if(*fd.name !='.')
            {
                  sprintf(szFrom,"%s\\%s",szFromDir,fd.name);
                  sprintf(szTo,"%s\\%s",szToDir,fd.name);

                  //check for subdirectories
                  sprintf(szFileName,"%s\\%s",szDir,fd.name);

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

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

return(0);
}

0
 
LVL 1

Author Comment

by:shrif
Comment Utility
jkr, repost as an 'answer'

0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
Comment Utility
Thanx shrif ;-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now