batch files - find current file directory

Asked

Viewed 128 times

1

I have a batch file that makes cmd point to another directory. But at a certain point, I need it to go back to the batch file directory itself. It is possible to do this?

2 answers

1

At the beginning of the code you can save the directory that the batch file is with the command:

set backDir=%cd%

And then go back to him with the command:

cd %backDir%

1


I suggest using the cd /d %~dp0: cd /d alters the current drive + the current directory to the drive and the directory where the batch was initially executed:

:: você pode criar uma variável:
set "_cd_batch_path=cd /d "%~dp0" "

:: ou simplesmente usar o command:

cd /d "%~dp0"

whenever it is necessary to return use the variable %_cd_batch_path% or simply "cd /d %~dp0":

%_cd_batch_path%

:: ou :: 

!_cd_batch_path!

:: ou ainda ::

cd /d "%~dp0"
  • Hello dear kapptuz, I understood what you said about >null and >nul, when you notice typos so you can comment directly on the answer, we are a community, all criticism and revision of text and code is accepted. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.