问题描述
我有一个包含多个.BAT文件中的一个特定的文件夹,我需要一个批处理脚本随机启动或拨打其中之一。
例如:
I have one certain folder that contains several .bat files and i need a batch script to randomly start or call one of them.Example:
a_abc_a.bat
a_abc_a.bat
b_abc_a.bat
b_abc_a.bat
a_abc_b.bat
a_abc_b.bat
b_abc_b.bat
b_abc_b.bat
正如你所看到的,所有的文件被命名为ABC。可有人解决这个我吗?
As you can see,all the files are named "abc".Can anyone solve this for me?
推荐答案
这应该工作。只需插入文件的正确数量。
This should work. Just insert the correct number of files.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET numberOfFiles=112
SET /a rand=%RANDOM%*%numberOfFiles%/32768+1
SET /a count=1
FOR /R %%f IN (*abc*.bat) DO (
IF !count!==%rand% (
CALL %%f
GOTO BREAK
)
SET /a count=!count!+1
)
:BREAK
这将工作只要文件被称为随机有 ABC
的疗法名称阿伯的.bat
在结束。请记住,你的主bat文件不得有ABC它的名字,也可能跻身其他批处理文件被调用(可能无限循环)。
This will work as long as the files to be called randomly have abc
in ther name aber .bat
at the end. Remember that your main bat file mustn't have abc in it's name or it might be called amongst the other bat files (possible infinite loop).
这篇关于从不同人物特定的文件夹开始随机批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!