I have a batch script which should go to several files and change it's content. Now I save a top directory as REPO_DIR and call a function.
cd %REPO_DIR%
echo Before call %cd%
CALL :update_config_xml "packages\com.company.sft\meta", package.xml, %mainapp_version%
echo After call %cd%
EXIT /B %ERRORLEVEL%
That function should change the directory and do the change and should set the current directory back to REPO_DIR.
:update_config_xml
echo Received directory %~1
cd %~1
echo Now cd within the function %cd%
@echo off
setlocal EnableDelayedExpansion
(FOR /F "delims=" %%a in (%~2) do (
set "line=%%a"
set "newLine=!line:Version>=!"
if "!newLine!" neq "!line!" (
set "newLine=<Version>%~3</Version>"
)
echo !newLine!
))> temp.xml
del %~2
ren temp.xml %~2
cd %REPO_DIR%
echo Now cd is %cd%
EXIT /B 0
My outfit file is something like this;
Before call E:\company\Repo-build
Received directory packages\com.company.sft\meta
Now cd within the function E:\company\Repo-build\packages\com.company.sft\meta
Now cd is E:\company\Repo-build
After call E:\company\Repo-build\packages\com.company.sft\meta
The last line is the problem. I cannot understand how it automatically changes back to the directory which was changed by the function.
Note that I have tried everything I could find here. I tried pushd and popd too. Got the same result. I don't think It will be a good solution to cd after every time I call this function.