0

I have the code:

@echo off
set /p dec="Path? "
set patha="C:\Users\%username%\%dec%"
set /a i=2
setlocal EnableDelayedExpansion
:import
if "%i%"=="12" goto loopend
if "!patha:~-%i%,1!"=="." set ext="!patha:~-%i%!"
set /a i=%i%+1
goto import
:loopend
echo %ext%
pause

It loops through the code 10 times, but when I have it echo "!patha:~-%i%,1!" and it echoes "." it doesn't set the ext variable. Am I doing comparisons wrong?

1 Answer 1

2

Works happily or me in W7, although

FOR /f %%i IN ("%patha%") DO SET ext="%%~xi"
echo %ext%

would seem to do the same thing.

That is, assuming you want to extract the last n characters starting "."... (that's not clear)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.