开发者

How to refer to random numbers in batch files (%random%)

开发者 https://www.devze.com 2023-03-05 05:58 出处:网络
I have come across a rather odd situation. I have generated a a random number in a batch file, which basically creates a file

I have come across a rather odd situation.

I have generated a a random number in a batch file, which basically creates a file

e.g. > %random%%random%.txt

Although, if I was to refer 开发者_如何学Goto this randomly generated file at a later stage in the script how would I accomplish this? (Baring in mind doing something like *.txt would not work, as there are hundreds of text files).


You simply save the generated value in a variable.

set x=%random%%random%
echo %x%
set filename=file%x%.txt
echo %x%
echo %filename%
find /n /v "" < %filename%
echo %x%
echo %filename%

Once they have been assigned using set, %x% and %filename% will not change again.

0

精彩评论

暂无评论...
验证码 换一张
取 消