Reputation: 15
I'm struggling with this problem, i'm new with batch scripting.
I have the absolute path of a file,
pathStr = "C:/a_folder/another_folder/com/project/files/my_file.properties"
And i need to know how can i extract the following part of that path.
subStr = "com/project/files/my_file" (without the extension of the file)
If this can help: the com
folder is always present in the absolute path. The only thing that varies are the names of the folders that are behind and in front of it
i don't know if this is possible, please can anybody give me a hint?
Upvotes: 1
Views: 56
Reputation: 130919
@echo off
setlocal
:: Define your starting full path
set "fullPath=C:/a_folder/another_folder/com/project/files/my_file.properties"
:: Remove the extension (also converts / into \)
for %%F in ("%fullPath%") do set "newPath=%%~pnF"
:: Remove the path before com\
set "newPath=%newPath:*\com\=com\%"
:: Display the result
echo newPath="%newPath%"
:: If you want to restore forward slashes for some reason
set "newPath=%newPath:\=/%"
:: Display final result
echo newPath="%newPath%"
--OUTPUT--
newPath="com\project\files\my_file"
newPath="com/project/files/my_file"
Upvotes: 1