Solved Batch Files - Tokens and Delimiters issue.

June 27, 2014 at 14:10:59
Specs: Windows 7
I have a simple string "ICJCL78SERIAL_yyyymmddhhmmss.CSV" that I am trying to parse to get "yyyymmddhhmmss". I use the following:
"FOR /f "tokens=2 delims=%FILE_NAME%" %%a IN ("%filename%") DO echo %%a"

However, the last 'second' digit gets truncated. eg. if I have a file "ICJCL78SERIAL_20140626104257.CSV", what I get is:
"2014062610425"; it misses the digit '7' before ".CSV". Why is that? Any help would be appreciated,
Thanks,

---AJ


See More: Batch Files - Tokens and Delimiters issue.

Report •

#1
June 27, 2014 at 14:26:20
✔ Best Answer
As the name says, a delimiter must be a single character that marks the begin or end of the token; so you have to code


for /F "tokens=2 delims=_." %%a in ("%filename%") do echo %%a


Report •

#2
June 27, 2014 at 16:54:51
Wow, I knew I was doing something silly, just couldn't get to it.

Obviously, this worked.... Thanks for your solution, appreciate it.

message edited by AJ11


Report •
Related Solutions


Ask Question