FOR LOOP Variable setting as %C - how to solve?
Posted: 20 Aug 2017 18:20
Hi Folks -
I'm building a process that uses the script name to build log,error, export etc directories. Therefore, I parse the name accordingly:
This works fine if the name is as such:
However, the client would like the option to name the file with 3 delimiters, as such:
The issue is when the code is as such:
it will set %C% as _%C if the file name only contains (3) strings. Can you help me put a check in there saying if there is only 3 delimiters, then set %C% to null.
Thanks!
I'm building a process that uses the script name to build log,error, export etc directories. Therefore, I parse the name accordingly:
Code: Select all
FOR /F "tokens=2* delims=_" %%A IN ("%~n0") DO (
IF ["%%A"] NEQ [""] SET "A=%%A"
IF ["%%B"] NEQ [""] SET "B=_%%B"
)
This works fine if the name is as such:
Code: Select all
STRING_STRING_STRING
However, the client would like the option to name the file with 3 delimiters, as such:
Code: Select all
STRING_STRING_STRING_STRING
The issue is when the code is as such:
Code: Select all
FOR /F "tokens=2* delims=_" %%A IN ("%~n0") DO (
IF ["%%A"] NEQ [""] SET "A=%%A"
IF ["%%B"] NEQ [""] SET "B=_%%B"
IF ["%%C"] NEQ [""] SET "C=_%%B"
it will set %C% as _%C if the file name only contains (3) strings. Can you help me put a check in there saying if there is only 3 delimiters, then set %C% to null.
Thanks!