Dec 5, 2002 #1 inetd Technical User Jan 23, 2002 115 HK Is there any function or API to copy a whole directory to a new destination? Thanks.
Dec 7, 2002 1 #2 BTecho Programmer Dec 7, 2002 108 US Sure. This works very well for me. int __fastcall CopyDir(AnsiString SourceDir, AnsiString DestDir) { char cSDir[MAX_PATH], cDDir[MAX_PATH]; memset(cSDir, 0, MAX_PATH); memset(cDDir, 0, MAX_PATH); strcpy(cSDir, SourceDir.c_str()); strcpy(cDDir, DestDir.c_str()); SHFILEOPSTRUCT dfstruct; ZeroMemory(&dfstruct, sizeof(dfstruct)); dfstruct.hwnd = Application->Handle; dfstruct.wFunc = FO_COPY; dfstruct.pFrom = cSDir; dfstruct.pTo = cDDir; dfstruct.fFlags = FOF_SILENT + FOF_NOCONFIRMATION; return SHFileOperation(&dfstruct); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString SourceDir="c:\\TestFrom", DestDir="c:\\TestTo"; if (DirectoryExists(SourceDir)) { SourceDir=SourceDir+"\\*.*"; if (!DirectoryExists(DestDir)){ if (!ForceDirectories(DestDir)) { ShowMessage("Cant Create Destination Folder" } else{ CopyDir(SourceDir, DestDir); } } } } //--------------------------------------------------------------------------- Also search for SHFILEOPSTRUCT in the Win32s Programmer's Reference help file for more info on the flags you can use. Upvote 0 Downvote
Sure. This works very well for me. int __fastcall CopyDir(AnsiString SourceDir, AnsiString DestDir) { char cSDir[MAX_PATH], cDDir[MAX_PATH]; memset(cSDir, 0, MAX_PATH); memset(cDDir, 0, MAX_PATH); strcpy(cSDir, SourceDir.c_str()); strcpy(cDDir, DestDir.c_str()); SHFILEOPSTRUCT dfstruct; ZeroMemory(&dfstruct, sizeof(dfstruct)); dfstruct.hwnd = Application->Handle; dfstruct.wFunc = FO_COPY; dfstruct.pFrom = cSDir; dfstruct.pTo = cDDir; dfstruct.fFlags = FOF_SILENT + FOF_NOCONFIRMATION; return SHFileOperation(&dfstruct); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString SourceDir="c:\\TestFrom", DestDir="c:\\TestTo"; if (DirectoryExists(SourceDir)) { SourceDir=SourceDir+"\\*.*"; if (!DirectoryExists(DestDir)){ if (!ForceDirectories(DestDir)) { ShowMessage("Cant Create Destination Folder" } else{ CopyDir(SourceDir, DestDir); } } } } //--------------------------------------------------------------------------- Also search for SHFILEOPSTRUCT in the Win32s Programmer's Reference help file for more info on the flags you can use.