Count a specific character [BATCH]
Solved
Vince
-
dubcek Posted messages 18627 Registration date Status Contributor Last intervention -
dubcek Posted messages 18627 Registration date Status Contributor Last intervention -
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
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 -____-
for /f "tokens=* delims=\" %%a in (chemin.txt) do (
pause
echo %%~na > format.txt
pause
I can't even reach the first pause -____-
il 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
)
Dir /b /s %location% >> chemin.txt
for /f "tokens=*" %%a in (chemin.txt) do (
pause
echo %%~na >> format.txt
pause
)