1

I'm not sure what is going wrong. I've been trying to follow code examples that I've found from other's that were asking a question along what I'm trying to do, and even have followed what the answers have said, and can't figure out what I'm doing wrong.

SET mypath=%~dp0
SET mypath=%mypath:~0,-1%

echo Selected Text file = %mypath%
SET STRING=%mypath%
echo %STRING%
pause
FOR /f "tokens=3* delimiters=\" %%i in ("%STRING%") do (
SET VAR= %%i
echo %%i
echo %VAR%
)
pause

the error that I get is that delimiters=\" was unexpected at this time.

1 Answers1

1

batch scripting language is not exactly the Shakespere's language

FOR /f "tokens=3* delims=\" %%i in ("%STRING%") do (

And as Dennis van Gils mentioned in the comments you need delayed expansion:

setlocal enableDelayedExpansion
SET mypath=%~dp0
SET mypath=%mypath:~0,-1%

echo Selected Text file = %mypath%
SET STRING=%mypath%
echo %STRING%
pause
FOR /f "tokens=3* delims=\" %%i in ("%STRING%") do (
  SET VAR=%%i
  echo %%i
  echo !VAR!
)
pause
npocmaka
  • 55,367
  • 18
  • 148
  • 187