Link to home
Start Free TrialLog in
Avatar of loudogz
loudogz

asked on

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
Avatar of Salte
Salte

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
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of loudogz

ASKER

Thanks, You da "Man"