943,766 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 10836
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Feb 17th, 2009
0

Re: Copy a Folder

Click to Expand / Collapse  Quote originally posted by niek_e ...
Here's the MSDN page for SHFileOperation. At the bottom of the page are all the error-codes (return values). So what value does it return in your case?
Print out the value of 'n' in the else statement to find out and thus find out what went wrong.
Thanks so much for your reply.
Yes, as your advice, i add the output of "n",
the result is "1026".(it should be 0x402)

By the MSDN:
0x402 An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Windows Vista and later.

So i guess the fail may from the "invalid path". is it right?
(But in my PC, the path is true, with out any problem.)
Could you help me and give me some suggestions?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pigg is offline Offline
6 posts
since Feb 2009
Feb 17th, 2009
1

Re: Copy a Folder

Click to Expand / Collapse  Quote originally posted by pigg ...
Yes, as your advice, i add the output of "n",
the result is "1026".(it should be 0x402)

By the MSDN:
0x402 An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Windows Vista and later.

So i guess the fail may from the "invalid path". is it right?
(But in my PC, the path is true, with out any problem.)
Both the pFrom and pTo members need to be double-null terminated, see the
SHFILEOPSTRUCT Structure documentation.
Reputation Points: 1105
Solved Threads: 389
Posting Virtuoso
mitrmkar is offline Offline
1,714 posts
since Nov 2007
Feb 24th, 2009
0

Re: Copy a Folder

Thank you so much for your advice.

The problem is solved.
I have add a "\0" to the end of the string, which should be a double null terminated(i think).
anyway, here is the solution:
C++ Syntax (Toggle Plain Text)
  1. std::string testto = "d:\\testto"
  2. SHFILEOPSTRUCT sf;
  3. memset(&sf,0,sizeof(sf));
  4. sf.hwnd = 0;
  5. sf.wFunc = FO_COPY;
  6. sf.pFrom = "d:\\testfrom";
  7. char d_te[] = "\0";
  8. std::string to = testto;
  9. to.append(d_te);
  10. sf.pTo = (LPCSTR) to.c_str();
  11. sf.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pigg is offline Offline
6 posts
since Feb 2009
Dec 30th, 2009
-1
Re: Copy a Folder
Click to Expand / Collapse  Quote originally posted by pigg ...
sorry, "failed" was printed.
and here is my code, i can not understand why...

C++ Syntax (Toggle Plain Text)
  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <CString>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. SHFILEOPSTRUCT sf;
  10. memset(&sf,0,sizeof(sf));
  11. sf.hwnd = 0;
  12. sf.wFunc = FO_COPY;
  13.  
  14. string from = "D:\\testfrom\\*.*";
  15. string to = "D:\\testto";
  16.  
  17. sf.pFrom = from.c_str();
  18. sf.pTo = to.c_str();
  19. sf.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI;
  20.  
  21. int n = SHFileOperation(&sf);
  22. if( n == 0)
  23. {
  24. cout << "Success\n";
  25. }
  26. else
  27. {
  28. cout << "Failed\n";
  29. }
  30. }
Try this...
C++ Syntax (Toggle Plain Text)
  1. string from = "D:\\testfrom\\*.*";
  2. string to = "D:\\testto";
  3.  
  4. sf.pFrom = (char*)malloc(from.length());
  5. sf.pTo = (char*)malloc(to.length());
  6. strcpy(sf.pFrom,(char*)from.c_str());
  7. strcpy(sf.pTo,(char*)to.c_str());
Reputation Points: 6
Solved Threads: 0
Newbie Poster
wavsyntax is offline Offline
8 posts
since May 2009
Jul 11th, 2010
0
Re: Copy a Folder
Hello,

I would really appreciate some help:
I’m using SHFileOperation function for copying folders from one place to another and it works great on XP OS.
Unfortunately, this function doesn’t work on Vista OS.
I’m wondering if somebody knows which function will work on both of them.

Thanks in advance,
Julia
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JuliaSh is offline Offline
1 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Having trouble with cin >> in xCode...
Next Thread in C++ Forum Timeline: Sockets and Vista





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC