0

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

1 Answer 1

2

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.