4

Created batch file:

@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
set execute counter=0
Set "Pass=45454545854545854254545454"
Echo Password is:%Pass%
start "" https://xxx.xxx/xxx/%pass%
:test
set "Pass=%Pass%"
set "Pass=!Pass:~1,-1!
echo Password is :%Pass%
start "" https://xxx.xxx/xxx/%pass%
goto test

Requirements: I want to open URL with given %pass% string, on each loop I want to strip the last character from string until one character will remain for URL.

Example:

1st url : https://xxx.xxx/xxx/45454545854545854254545454
2nd url : https://xxx.xxx/xxx/4545454585454585425454545
.......
last url : https://xxx.xxx/xxx/4
2
  • 2
    set "Pass=%Pass%" is useless. Also, set "Pass=!Pass:~1,-1! will remove first and last number/character. Commented Dec 13, 2018 at 17:37
  • A typo: echo instead of eacho. Commented Dec 13, 2018 at 17:41

2 Answers 2

5

You can accomplish this with much less code.

@echo off
Set "Pass=45454545854545854254545454"
:loop
echo https://xxx.xxx/xxx/%pass%
set "pass=%pass:~0,-1%"
IF DEFINED pass GOTO loop
Sign up to request clarification or add additional context in comments.

Comments

4

Here is a possible solution:

@echo off
Setlocal EnableExtensions EnableDelayedExpansion
set "execute counter=0"
Set "Pass=45454545854545854254545454"
Echo Password is: %Pass%
start "" https://xxx.xxx/xxx/%pass%
goto test

:test
set "Pass=!Pass:~0,-1!"
if defined Pass (
   echo Password is: !Pass!
   start "" https://xxx.xxx/xxx/!pass!
   rem pause
   rem Add pause not to overload your computer!
   goto test
) else (
   echo No more characters to strip!
   pause
   exit /b
)

I have quoted execute counter variable in set to avoid any strange behaviours. Added a goto test after the end of main code (not really needed).

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.