On my old VPS I was using the following code to copy the files and directories within a directory to a new directory that was created after the user submitted their form.
Why not just ask the OS to take care of this?
system("cp -r olddir newdir");
Done.