batch FOR /F and space in file/pathname and usage of token?
-
15-04-2021 - |
Вопрос
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!
Решение
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
Другие советы
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:
- Store first token into %%a (i.e.
D
) - Store the rest of the line into %%b