batch FOR /F and space in file/pathname and usage of token?

1.3k views Asked by At

I am using a batch file to update only those files that have changed in my SVN repository. This is a part of my batch file:

SET CHANGES=svnlook changed c:\myrepository
FOR /F "usebackq tokens=2" %%a IN (`%CHANGES%`) DO (echo %%a)

I only get dok instead of dok version1.txt and I guess thats because of the space. How must I change the code to get the filename even if there is a space? Is that because of the tokens or where does it cut the name?

The output of svnlook looks like:

D Testprojekt/trunk/dok - Kopie (2).txt
D Testprojekt/trunk/dok - Kopie (3).txt
D Testprojekt/trunk/dok - Kopie (4).txt

So I am using tokens=2 to only get the path (Testprojekt/trunk/dok - Kopie (2).txt) and not the action (D=deleted for example).

Thanks!

2

There are 2 answers

2
Grhm On BEST ANSWER

Try using:

FOR /F "usebackq tokens=1,*" %%a IN (`%CHANGES%`) DO (echo %%b)

This assigns the first token to %a and all subsequent ones to the next letter i.e. %b

0
Álvaro González On

With this output:

D Testprojekt/trunk/dok - Kopie (2).txt
D Testprojekt/trunk/dok - Kopie (3).txt
D Testprojekt/trunk/dok - Kopie (4).txt

... you can try this:

FOR /F "usebackq tokens=1*" %%a IN (`%CHANGES%`) DO (
    echo %%b
)

The tokens=1* bit means:

  1. Store first token into %%a (i.e. D)
  2. Store the rest of the line into %%b