[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

FILE FUNCTIONS: is there a function to copy a whole folder?

Hi,

I was just wondering if there is a function to copy a whole folder...I know there is CopyFile.

BOOL CopyFile(
  LPCTSTR lpExistingFileName,
                          // pointer to name of an existing file
  LPCTSTR lpNewFileName,  // pointer to filename to copy to
  BOOL bFailIfExists      // flag for operation if file exists
);
 
But I can't find anything to copy a whole folder...

Thanks in Advance..

Lou
0
loudogz
Asked:
loudogz
1 Solution
 
SalteCommented:
Yes there is, not sure if you like the answer though. Since I see from your post that you're in a windoze machine I'll give you the answer for windows:

system("xcopy /s...other options...args..");

You can also use CreateProcessEx() or something like that instead of system() but the net result is more or less the same.

Under unix the system("cp -r source... dest"); should work.

This was perhaps not the answer you were looking for but it does the job.

You can also use FindFirstFile()/FindNextFile() and copy the directory that way. Check the flag ISDIR for directory, if directory you copy it by recursively calling yourself to copy it. If it is a plain regular file you call CopyFile() to copy the file.

Alf
0
 
jkrCommented:
Use 'SHFileOperation()', it is designed for that purpose:

    SHFILEOPSTRUCT  sfo;
    ZeroMemory  (   &sfo,   sizeof  (   SHFILEOPSTRUCT));

    sfo.wFunc   =   FO_COPY;
    sfo.pFrom   =   "c:\\path\\*.*";
    sfo.pTo     =   "c:\\anotherpath";
    sfo.fFlags  =   FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI;

    if  (   SHFileOperation (   &sfo))
        {
            // error
        }
0
 
loudogzAuthor Commented:
Thanks, You da "Man"
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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