Find directory name of a .bat file

0

I have a .bat file that does some iterations via cmd across multiple directories. My problem is this:

  • I need to be able to get the directory of the .bat file itself to keep coming back to it for other iterations.

An example would be:

:exemplo
set file=C:\nome-do-diretorio\
for /f "tokens=*" %%A in (%file%) do ( cd %%A)

So far, okay, but then I need the cmd to be pointed to the directory of the bat file itself.

    
asked by anonymous 29.08.2018 / 14:25

2 answers

0

You can use %~dp0

@echo off
echo "%~dp0"
    
29.08.2018 / 22:18
2

You can use %cd% , this will return the current path where the batch is running.

You can test with echo %cd%

    
29.08.2018 / 15:07