i write this code in C++ Builder to copy some folders from a network folder mounted on x: (eg x:\games\foldername) to a local path: d:\program files. I use shfileopstruct as follow.
The source path (s variable) is taken from database using FieldByName("path") and then it is given a prefix ("x:\games\" and a "\0" as MSDN suggests . SHFILEOPERATION works fine as it is.. but the unusual thing is than when i remove the code about ShowMessage(path) (which i have for validation), SHFILEOPERATION do fail.
Any suggestions about this? Am I missing something? I would appreciate your help as i am not experienced. Thanks in advance.
UnicodeString s=""; //source path
UnicodeString d=""; //destination
UnicodeString path=""; //path from database field
if(ClientDataSet1->Active==false)
ClientDataSet1->Open();
path=ClientDataSet1->FieldByName("path")->Text; //get [path] value from db
ShowMessage(path); /// !!!! <<<-------- ??? SHOWMESSAGE ???
s="x:\\games\\" + path + "\0" ;
d="d:\\program files\0" ;
// Create the SHFILEOPSTRUCT and zero it.
SHFILEOPSTRUCT fos;
memset(&fos, 0, sizeof(fos));
fos.hwnd = Handle;
fos.wFunc = FO_COPY;
fos.pFrom = s.c_str();
fos.pTo = d.c_str();
fos.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMMKDIR;
int n=SHFileOperation(&fos);
if(n)
ShowMessage(n);
else
ShowMessage("OK");