Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open URLs with given string | strip one character from string on each URL run

Tags:

batch-file

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
like image 576
RAJA Avatar asked Jan 01 '23 12:01

RAJA


2 Answers

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
like image 78
Squashman Avatar answered Jan 04 '23 01:01

Squashman


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).

like image 37
double-beep Avatar answered Jan 04 '23 00:01

double-beep