"Visual Studio cannot be installed in a non-empty directory". This issue occurs during installation because Visual Studio has already been installed in that directory with the same edition.
Check the Installation Directory
You can go and check that location, and you will find Visual Studio there. As you can see, I have the Community Edition installed, and I am trying to install the Community Edition again. One solution is to delete the existing Community Edition and then try installing it again.
I navigated to the following path: "C:\Program Files\Microsoft Visual Studio\2022" as shown in the screenshot above, and found that the Community Edition is already present.
Solution 1: Change New Installation Directory
After setting new installation path click on Install to continue without any issue.
Solution 2:Clear Existing Installation Directory
If there are files or folders in the installation directory, you need to delete them. Make sure to remove any leftover files from previous installations
Conclusion
By following these steps, you should be able to resolve the "Visual Studio cannot be installed on a non-empty directory" error effectively. Ensuring that your installation directory is empty or selecting a new one will allow you to proceed with your Visual Studio installation without further complications.