?
Solved

How to copy entire folder structure from C++?

Posted on 1999-01-19
7
Medium Priority
?
868 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:luisr
ID: 1419019

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
ID: 1419020
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
ID: 1419021
Hmm - this can be done much easier, 'SHFileOperation()' should do the job...
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 1

Author Comment

by:shrif
ID: 1419022
thanks.
0
 

Expert Comment

by:ramrocket
ID: 1419023
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
ID: 1419024
jkr, repost as an 'answer'

0
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 1419025
Thanx shrif ;-)
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

764 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