I am trying to copy a folder by SHFileOperationA
function. Here is my code.
int main() {
SHFILEOPSTRUCTA sf;
int result;
string source = "D:\\check\\folder4";
string dest = "D:\\Documents\\test\\folder4";
sf.pFrom = source.c_str( );
sf.pTo = dest.c_str( );
sf.wFunc = FO_COPY;
sf.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_SILENT;
result = SHFileOperationA(&sf);
return 0;
}
I am not able to understand that how to make the string appended by \0
twice.
I tried something like this.
string source = "D:\\check\\folder4\\0\\0";
string dest = "D:\\Documents\\test\\folder4\\0\\0";
But, it is not working. I have also tried few more combinations but none of them is working. Please can anyone suggest me how to solve this?
I can solve the problem by directly assigning the paths like this:-
sf.pFrom = "D:\\check\\folder4";
sf.pTo = "D:\\Documents\\test\\folder4";
and the problem gets solved but my intention is to make use of strings. Please can anybody help me with this.
Also, if possible can anybody tell me why directly assigning the string constant i.e sf.pFrom = "D:\\check\\folder4";
is working and assigning using a string like sf.pFrom = source.c_str( );
is not working?
Thanks in advance.