Reputation: 33
A directory named such as CD_25467, JBMA_33455, CCD_2133, etc, I want to store the character and numbers in two different variables. For example,
CD_25467
@echo off
set folder=D:\karthick\CD_25467
set j=[(A-Z)+]
set a=[(0-9)+]
echo %j%
echo %a%
The output will come,
CD
25467
How to write regex coding for the above example?
Upvotes: 0
Views: 57
Reputation: 49085
Use in batch file:
@echo off
for %%I in ("D:\karthick\CD_25467") do for /F "tokens=1,2 delims=_" %%A in ("%%~nI") do set "j=%%A" & set "a=%%B"
echo %j%
echo %a%
Open a command prompt window and run for /?
for help on command FOR explaining what %~nI
means which references name of file or folder, i.e. the string between last backslash and last dot if there is such a string at all. A folder path ending with a backslash would result in running the inner FOR with just ""
resulting in j
and a
still not defined or keeping their current string values.
The help explains also the syntax on usage of option /F
to split one or more lines read from a text file or a single string as done here or captured lines output by a command line executed in background with cmd.exe /C
.
Upvotes: 1