I would like to append two strings together so that I can rename a file using the MoveFile function. But my strings refuse to concatenate, so instead of adding “E:\” to “FILE-%s-%02d%02d%02d-%02d%02d.txt” to give me “E:\FILE-%s-%02d%02d%02d-%02d%02d.txt”, it gives me just “E:\” as if nothing happened.
Here is a snippet of my full code:
drivePathAgain = "E:\\";
sprintf(newname, "FILE-%s-%02d%02d%02d-%02d%02d.txt", szVolNameBuff, lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute);
lstrcat((LPWSTR)drivePathAgain, (LPWSTR)newname);
result = MoveFile((LPCWSTR) drivePath, (LPCWSTR) drivePathAgain );
I can’t append newname to drivePathAgain. If you need me to post the entire code to get the big picture, I can. Is there a way to append strings like that?
Thanks
Based on your casting to
LPWSTR, I would assume your project is setup in Unicode mode. That means functions likelstrcpyandMoveFileare accepting pointers to strings ofwchar_tnotchar. If you don’t know what this means, you need to research the difference between Ascii and Unicode.I would suspect that may be the source of your problem. And even if it isn’t, casting from
char*towchar_t*(also known asLPWSTR) will likely cause problems for you eventually. Casting pointers is not the same as converting from one of those string types to the other.