This part of my programm tries to rename all folders and subfolders. All other functionality is in another code, here I'm just renaming a single folder by providing a path.
Since rename doesnt seem to work for me I tried using MoveFile.
I understand that it requires an LPCTSTR value.. but the paths I am currently providing (casted from std::filesystem::directory_entry -> std::filesystem::path) -> LPCTSTR) aren't accepted.
I'm getting that I'm not casting it the right way and I probably have to provide it with an "L" in front of the variable, but I can't find nor figure out the syntax.
bool renameFolder(std::string confirmStr3, auto dirEntry, std::string& replacedStr, std::string& insertStr, int& foldername_replacements)
{
std::string path_string = dirEntry.path().string();
path_string = std::filesystem::path(path_string).filename().string();
replace_all(path_string, replacedStr, insertStr);
path_string = getFolderPath(std::filesystem::path(dirEntry).string()) + "\\" + path_string;
if (std::filesystem::path(dirEntry) != std::filesystem::path(path_string))
foldername_replacements++;
//std::filesystem::rename(std::filesystem::path(dirEntry), std::filesystem::path(path_string));
MoveFile(LPCTSTR(std::filesystem::path(dirEntry)), LPCTSTR(std::filesystem::path(path_string)));
}

You can't type cast a
std::filesystem::pathobject directly to a character pointer. That is exactly what the error message is telling you. And you can't use theLprefix with variables, only with compile-time literals.You need to call the
path::c_str()method instead, eg:Or, call the
path::(w)string()method, and then callc_str()on the returnedstd::(w)stringobject, eg:That being said,
std::rename()is likely to be implemented on Windows usingMoveFile/Ex()internally, so this is a possible XY Problem.std::rename()is the preferred solution, so you should focus your efforts on figuring out why it is not working for you.UPDATE:
On a side note, the code you have shown makes repetitive use of temporary
std::filesystem::pathobjects that are unnecessary. Try simplifying the code, like this: