使用给定的字符串打开URL |在每个运行的URL上从字符串中删除一个字符

时间:2018-12-13 17:12:37

标签: 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

要求:我想用给定的%pass%字符串打开URL,在每个循环中,我想从字符串中去除最后一个字符,直到URL保留一个字符为止。

示例:

1st url : https://xxx.xxx/xxx/45454545854545854254545454
2nd url : https://xxx.xxx/xxx/4545454585454585425454545
.......
last url : https://xxx.xxx/xxx/4

2 个答案:

答案 0 :(得分:4)

这是一个可能的解决方案:

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

为了避免出现任何奇怪的行为,我在execute counter中引用了set变量。在主代码末尾添加了goto test(不是真正需要的)。

答案 1 :(得分:4)

您可以用更少的代码来完成此操作。

@echo off
Set "Pass=45454545854545854254545454"
:loop
echo https://xxx.xxx/xxx/%pass%
set "pass=%pass:~0,-1%"
IF DEFINED pass GOTO loop