Reputation: 2814
I have this folder structure:
C:\SomeFolder\SubFolder\Version\Version_IMS
I have a batch script in C:\SomeFolder\SubFolder\Version that needs to enter the directory Version_IMS
The version can be for example 5.3.12.0 and is not constant as it changes. So I cannot know it.
I need in the script to extract the last directory it is in for example 5.3.12.0 and then I can enter to 5.3.12.0_IMS.
What is the easiest way to achieve it?
Upvotes: 0
Views: 42
Reputation: 70923
for %%a in ("%~dp0.") do cd /d "%%~fa\%%~nxa_IMS"
Where
%~dp0
is the drive and path of the current batch file
%%~fa
is the full path to the element being referenced by the for
replaceable parameter %%a
%%~nxa
is the name and extension of the element being referenced by the for
replaceable parameter %%a
.
So, we retrieve a reference to the folder that contains the batch file, get the name of that folder and use it to enter (i have used cd
) into the child folder
Upvotes: 1