我想提取路径字符串中的第一个数字.
一些例子
c:\dir\release1\temp should extract: 1
c:\dir\release11\temp should extract: 11
c:\dir\release1\temp\rel2 should extract: 1
c:\dir\release15a\temp should extract: 15
Run Code Online (Sandbox Code Playgroud)
我当前的代码,循环文件夹名称,并测试文件夹名称是否为数字(我需要在这里进行一些更改):
setlocal enableextensions enabledelayedexpansion
set line=one\two\three\4\pet\0\sest\rel6\a
rem set line=%cd%
:processToken
for /f "tokens=1* delims=\" %%a in ("%line%") do (
echo Token: %%a
set line=%%b
rem need fix here: need to extract number from string
echo %%a|findstr /r /c:"^[0-9][0-9]*$" >nul
if errorlevel 1 (echo not a number) else (echo number)
)
if not "%line%" == "" goto :processToken
endlocal
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑:我想解析该路径字符串中的数字.好吧,我找到了只检查字符串的最后3个字符的解决方案.现在好了.
::test last …Run Code Online (Sandbox Code Playgroud)