:bof
@echo off & setlocal enableextensions enabledelayedexpansion
set fpath=C:\workspace\projctes\fitNesseRoot\FrontPage\TestSuite\TestCase1
set count=0
set rest=%fpath%
:init
echo %fpath% | find /i "FrontPage"
if errorlevel 1 (
echo # ERROR & goto :eof
) else (
goto :loop
)
:loop
for /f "tokens=1* delims=\" %%a in ("%rest%") do (
set /a count+=1
set fpath[!count!]=%%a
set rest=%%b
if defined rest goto loop
)
for /l %%i in (1,1,%count%) do set fpath[%%i]=!fpath[%%i]!
set testpath=%fpath[5]%\%fpath[6]%
set testcase=%fpath[7]%
echo %testpath%
echo %testcase%
:eof
:bof
@echo off & setlocal enableextensions enabledelayedexpansion
::%~dp0 is the Windows equivalent of `pwd` in bash.
for /f "usebackq" %%i in (`cd`) do set fpath=%~dp0
echo Full path is %fpath%
:init
::check string contains frontpage
echo %fpath% | find /i "FrontPage"
if errorlevel 1 (
echo # ERROR & goto :eof
) else (
goto :loop1
)
::break into last and the rest part
:loop1
for %%a in ("%fpath%") do set testpath=%%~pa & set testcase=%%~na
:loop2
for /f "tokens=1,* delims=\" %%a in ("%testpath%") do (
set first_=%%a
set testpath=%%b
)
echo %testpath% | findstr /b /i "FrontPage" >nul
if not errorlevel 1 goto next
if defined testpath goto loop2
:next
echo test path is %testpath%
echo test case is %testcase%
:eof
Will The Path Always be This long
C:\workspace\projctes\fitN
or it can vary like this
C:\workspace\projctes\fitN
C:\workspace\projctes\fitN
C:\workspace\projctes\fitN
we can extract the each folder in the path like this
Open in new window