tags:

views:

30

answers:

1

hi,

How to copy a folder from one drive to other drive in VC++ ...?

I have come this far

   String^ SourcePath = Directory::GetCurrentDirectory();
   String^ DestinationPath = "c:\\Test";
   CString s(SourcePath) ;
   CString d(DestinationPath);
   Directory::CreateDirectory(DestinationPath);

 SHFILEOPSTRUCT*  pFileStruct = new SHFILEOPSTRUCT;
 ZeroMemory(pFileStruct, sizeof(SHFILEOPSTRUCT)); 
 pFileStruct->hwnd  = NULL;
 pFileStruct->wFunc = FO_COPY;
 pFileStruct->pFrom = (LPCWSTR)s;//"D:\test_documents\test1.doc"; 
 pFileStruct->pTo =  (LPCWSTR)d; 
 pFileStruct->fFlags = FOF_SILENT  | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR ; 
 bool i = pFileStruct->fAnyOperationsAborted ;
 int status = SHFileOperation(pFileStruct);

 if(status == 0)
 {
           return true;
 }
 return false;

the status is showing 2 instead of zero , can some one tell me why..?

+2  A: 

Usually a String^ points to a managed string object. The SHFILOPSSTRUCT must befilled with pointers to unmanaged wchar_t. So you must pin the strings and convert. You tried to use the CString class as conversion helper.

Use the PtrToStringChars instead to get valid strings in pTo and pFrom: http://msdn.microsoft.com/en-us/library/d1ae6tz5(VS.80).aspx

The read of the fAnyOperationsAborted member is not required for the operation.

harper
Thats cool, I got it, Thank you very much..!!
rajivpradeep