'Why is a folder not deleted with RMDIR in batch file as last command?

I have the following code in a .bat file:

@echo off
xcopy /Y /S %CD%\Code\Release C:\Users\%USERNAME%\Desktop\ShareIt /I
cls
cd C:\Users\%USERNAME%\Desktop\ShareIt\
call "Trabalho AEDA.exe"
xcopy /Y /S C:\Users\%USERNAME%\Desktop\ShareIt\FICHEIROS\ %CD%\Code\Release\FICHEIROS\
RMDIR /S /Q C:\Users\%USERNAME%\Desktop\ShareIt

That copies a folder to a location, runs the .exe from it and then it overwrites the original files in my folder and has do delete the ones initially copied.

The folder I copy to the user desktop has other folder inside, and the .exe. At the final line of the .bat, it deletes everything in the folder, but the folder is kept in the Desktop folder. I want to delete it, too. I tried several instructions, but without success.

EDIT: That was the issue, thanks guys.



Solution 1:[1]

ShareIt folder isn't deleted probably because you are in the folder. So, adding cd .. before RMDIR /S /Q C:\Users\%USERNAME%\Desktop\ShareIt solves it.

Solution 2:[2]

Since you execute

cd C:\Users\%USERNAME%\Desktop\ShareIt\

It's the current directory when you execute the now delete the directory command.

Move to another directory, and then try the deletion

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kaitoy
Solution 2 Magoo