Reputation: 109
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 to 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).
Upvotes: 2
Views: 612
Reputation: 19457
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.
Upvotes: 3