batch files - find directory of the current file

0

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?

    
asked by anonymous 28.08.2018 / 14:48

2 answers

0

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%
    
02.09.2018 / 01:46
0

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"
    
16.12.2018 / 17:42