I have a batch file that takes one argument which is a comma separated string and I'm calling it like this:
myBatch.bat ".git,*.tmp,file.c"
Inside the batch file I need to write a code that parses the argument that is passed at the command line and break it like this:
@echo off
set excludes=%~1
set excludes_cmd=""
FOR /f "tokens=1* delims=," %%a IN ("%excludes%") DO (
set "excludes_cmd=%%excludes_cmd%% --exclude %%~a"
)
So at the end, when I pring the 'excludes_cmd' variable I will get this:
--exclude .git --exclude *.tmp --exclude file.c
FOR /Fthen you need to know how many tokens you will have passed to the script. In your case it is three, so you would be usingtokens=1-3and%%a,%%band%%c. But you would be better off using a normalFORcommand.FOR %%a in (%~1) DO (call set "excludes_cmd=%%excludes_cmd%% --exclude %%~a"forloop will resolve wildcards like*and?, but I believe this is not what the OP wants...forresolves wildcards (*,?),for /Fneeds a predefined number of items (tokens), sub-string replacement does not care about quotation (I guess there could also occur quoted strings like'.txt'in the argument, which could even contain,on their own, like'x,y'; right? such commas need to be preserved then)...