Count a specific character [BATCH]
Solved
Hello,
I have a line:
M:\folder\hello\test
I would like to count the number of "\" and add 2 to it.
Actually, I need this value for the tokens of a for loop that processes the files in this folder using "\". More clearly, I need the 5th element of the URL in this example.
M:\folder\hello\test
1 \ 2 \ 3 \ 4 \ 5
Here is my code so far:
set localisation= M:\folder\hello\test
set nbreDossier=5
dir /b /s %location% > path.txt
for /f "tokens=%nbreDossier% delims=\" %%i in (path.txt) do (
...
)
In fact, this will help me make my script dynamic... I will then have:
set /p localisation=enter the location
and the token value will be calculated automatically.
I have a line:
M:\folder\hello\test
I would like to count the number of "\" and add 2 to it.
Actually, I need this value for the tokens of a for loop that processes the files in this folder using "\". More clearly, I need the 5th element of the URL in this example.
M:\folder\hello\test
1 \ 2 \ 3 \ 4 \ 5
Here is my code so far:
set localisation= M:\folder\hello\test
set nbreDossier=5
dir /b /s %location% > path.txt
for /f "tokens=%nbreDossier% delims=\" %%i in (path.txt) do (
...
)
In fact, this will help me make my script dynamic... I will then have:
set /p localisation=enter the location
and the token value will be calculated automatically.
Configuration: Windows XP Firefox 3.5.2
6 answers
-
It doesn't work.
-
Contributor%%a in a .bat
-
dir /b /s %location% > chemin.txt
for /f "tokens=* delims=\" %%a in (chemin.txt) do (
pause
echo %%~na > format.txt
pause
I can't even reach the first pause -____- -
Contributoril manque ), utiliser >> et on peut supprimer delims=\:
Dir /b /s %location% >> chemin.txt
for /f "tokens=*" %%a in (chemin.txt) do (
pause
echo %%~na >> format.txt
pause
)-
-
@VinceUh no actually, sorry guy, your thing is working great, there was an unexpected change... but everything is good now, thanks again and sorry
++
Have a good life -
-
-
Uh... actually I'm going to seem a bit silly but... let's say that... your solution has been working from the start... it's just that I wrote tockens -___- anyway, it's resolved now, thx so so much
++
Vince -
Contributorhello
if you just want the last element, you can use %~na:
$ type zz
1\2\3\4\5
$ for /f "delims=\ tokens=*" %a in (zz) do @echo %~na
5