I have created a small batch file for windows, and I am having a small issue:
I defined a variable which contains a string, the path of a source file:
D:\git_repos\ALM_Sandboxs\Sensor_Config\StateManagement\ssm_state.cpp
I ´d like to extract the path without the file name:
D:\git_repos\ALM_Sandboxs\Sensor_Config\StateManagement\
Since the path can change, and so does the file name, I am having difficulties to do this. There are many ways, but I wasn´t able to use any of them:
The first one would be to count charaters of the file name:
set NumberOfCharacter
and do
set FilePath=%FilePathTemp2:~,%NumberOfCharacter%%
But this doesn´t work. I can only use number with this syntax:
set FilePath=%FilePathTemp2:~,-18% ==> This works, but I´d like to read 18 from a variable
I have read that the batch interpreter can´t resolve the % pairs, so I tried
for /l %%x in (1,1,%strlength%) do set %FilePathTemp2%=%FilePathTemp2:~,-1%
It doesn´t work either, because the for loop seems not able to change FilePathTemp2 with a global scope.
I would be thankfull for any help