Here is an example of how to copy all the subfolders and files to a new destination folder. Looks like you are using managed code, so I don't know how to use unmanaged win32 functions in managed programs.
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
SHFILEOPSTRUCT sf;
memset(&sf,0,sizeof(sf));
sf.hwnd = 0;
sf.wFunc = FO_COPY;
sf.pFrom = "d:\\masm32\\*.*";
sf.pTo = "d:\\masm33";
sf.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI;
int n = SHFileOperation(&sf);
if( n == 0)
{
cout << "Success\n";
}
else
{
cout << "Failed\n";
}
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
You can't convert a std::string to a LPCSTR, you'll have to convert it manually. This can be don with the std::string memeber c_str() So change this:
sf.pFrom = ss;
sf.pTo = st;
to this:
sf.pFrom = ss.c_str();
sf.pTo = st.c_str();
And it should work!
Next time if you post code use code-tags .
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Does it print 'succes' or 'failed'?
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
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.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
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.
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395