Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy whole directory 1

Status
Not open for further replies.

inetd

Technical User
Jan 23, 2002
115
HK
Is there any function or API to copy a whole directory to a new destination?

Thanks.
 
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.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top