Extract number from string in batch file

后端 未结 4 650
余生分开走
余生分开走 2021-01-07 06:54

From a batch file I want to extract the number 653456 from the following string:

C:\\Users\\testing\\AppData\\Local\\Test\\abc123\\643456\\VSALB         


        
4条回答
  •  鱼传尺愫
    2021-01-07 07:18

    EDIT - Code sample adapted to correct errors shown in comments

    set d=C:\Users\testing\AppData\Local\Test\abc123\643456\VSALBT81_COM
    for %%f in ("%d:\=" "%") do for /f %%n in ('echo %%f^|findstr /b /e /r "\"[0-9]*\""') do (
        echo %%~n
    )
    

    Just precede the path with a quote, split the path, replacing each backslash with a quote a space and a quote and append a quote (so we have a list of elements to iterate), and for each part check if it is formed only by numbers

提交回复
热议问题