You can use variables and also their value/attribute/property expansions.
In the code below you have some variables that are fixed and you have others that are changed according to the actions of bat
, as an example in directory exchanges.
@echo off & cd /d "%~dpn0"
for %%i in ("%windir%" "%appdata%" "%ALLUSERSPROFILE%")do cls & cd /d "%%~i" & call :^)
goto :eof
:^)
echo/ ----------------------------------------------------------------
echo/ variaveis nao alteram seus valores
echo/ ----------------------------------------------------------------
echo/ %%~d0 = %~d0
echo/ %%~p0 = %~p0
echo/ %%~dp0 = %~dp0
echo/ %%~f0 = %~f0
echo/ %%~dpnx0 = %~dpnx0
echo/ ----------------------------------------------------------------
echo/ pasta atual: %__CD__%
echo/ ----------------------------------------------------------------
echo/ variaveis alteram seus valores para pasta atual
echo/ ----------------------------------------------------------------
echo/ %%CD%% = %cd%
echo/ %%__CD__%% = %CD%
echo/ ----------------------------------------------------------------
timeout -t 5 & exit /b
Note: 1) More information about the variable expansions you have in the help co command for /?
Note: 2) You can set a variable to use when returning to the directory where the bat initially ran in this way:
set "_pasta_bat=%~dp0"
rem :: retornando para a pasta do bat ::
cd /d "%_pasta_bat%"
rem :: ou apenas ::
cd /d "=%~dp0"
In the powershell is
(Get-Location).Path
!– Marconi