I have a batch file that causes the cmd to point to another directory. But at some point, I need it to go back to the batch file's own directory. Is it possible to do this?
I have a batch file that causes the cmd to point to another directory. But at some point, I need it to go back to the batch file's own directory. Is it possible to do this?
At the beginning of the code you can save the directory where the batch file is with the command:
set backDir=%cd%
And then go back to it with the command:
cd %backDir%
I suggest using cd / d% ~ dp0: cd / d changes the current drive + the current directory to the drive where batch was initially run :
:: você pode criar uma variável:
set "_cd_batch_path=cd /d "%~dp0" "
:: ou simplesmente usar o command:
cd /d "%~dp0"
Whenever necessary, use the variable %_cd_batch_path%
or simply "cd /d %~dp0"
:
%_cd_batch_path%
:: ou ::
!_cd_batch_path!
:: ou ::
cd /d "%~dp0"