Clean code project fails to generate project files

Here is the error:

Running D:/Program/EpicGames/UE_4.23/Engine/Binaries/DotNET/UnrealBuildTool.exe  -projectfiles -project="C:/Test/Test.uproject" -game -rocket -progress
ERROR: Unhandled exception: System.IO.IOException: Cannot create "C:\Users\[USER]\AppData\Local\UnrealEngine" because a file or directory with the same name already exists.
          at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
          at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
          at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
          at UnrealBuildTool.XmlConfig.ReadConfigFiles(FileReference OverrideCacheFile) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\System\XmlConfig.cs:line 131
          at UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 444

I first noticed the problem when trying to install a 3rd party plugin on a clean blueprint project. I would get the error that modules were missing and needed to rebuild - the error was the same: ERROR: Unhandled exception: System.IO.IOException: Cannot create “C:\Users[USER]\AppData\Local\UnrealEngine” because a file or directory with the same name already exists. The project would not open due to this error.

After a lot of trial and error and trying a lot of solutions I decided to try a simple clean code project, without any plugins. I deleted the plugin folder, started from scratch. Tried building a project in a different folder. Every time the build fails and the error is always the same. I cannot open any c++ project.

I have tried clearing the TEMP folder, I have tried deleting the folder that is mentioned in the error, I have verified the engine version, I have tried doing all the same steps with 4.22.3, nothing works, error remains the exact same.

I believe it has to be either an issue with UnrealBuildTool or the system variables, but can’t figure out how to solve it.

Clean blueprint project open with no issues.

Any help would be very appreciated.

Nevermind, managed to solve it with a full uninstall and reinstall process, cleaning everything along the way. Error no longer happens, can now open c++ projects and add plugins.

Steps were: deleting all engine versions, then the launcher, restarting, deleting all Unreal associated folders from both the Programs folder and from user/AppData, cleaning up registry related to Unreal, restarting again, and then reinstalling.