I am porting a codebase that depends on Win32 API to C++ 17. There is a class that is responsible for handling files. The function I am currently looking at looks like this:
bool project::filesystem::FileSystem::rename(const std::string& oldFileName, const std::string& newFileName)
{
#if defined(_WIN32) || defined(WIN32)
BOOL res = ::MoveFileEx(nativePath(oldFileName, false).c_str(),
nativePath(newFileName, false).c_str(), MOVEFILE_WRITE_THROUGH);
return (res != FALSE);
#else
#pragma message("FileSystem::rename() not implemented on non-Windows OS.");
return false;
#endif
}
where project::filesystem::FileSystem::nativePath(...)
converts a string that contains a path to the native representation.
The compiler is MSVC v141, so I need to use std::experimental::filesystem
and the full set of features might not be present. Is there an equivalent to MoveFileEx(...)
or do I have to combine copy(...)
with remove_all(...)
?