%random%
will be constant throughout all iterations of the loop. You would need to enable delayed expansion and use !random!
instead. But I would not even do that because !random!
can give duplicate values. Unlikely, but possible. If it were not possible for duplicates, then it would not be random.
I would simply append .b64
to the original name.
You don't need FINDSTR to filter out the header/footer. There are options to control the format of the CERTUTIL output.
I assume you want the encoded output files in the same directory as the source.
Since the arguments will be a series of file names (paths), you can simply iterate %*
with FOR.
@echo off
for %%F in (%*) do certutil -encodehex -f %%F %%F.b64 1
Another nice result of the above - you can call the script on the command line with wildcards, and the FOR loop will iterate all matching files.
But there is one potential problem when you drag and drop - Windows properly encloses the file in quotes if it has spaces. But it does not enclose the file in quotes if the name has &
without any spaces.
So if you drag and drop any file names with &
that don't contain space, then the simple solution above will fail.
The code is much more complicated if you want to handle drag and drop with &
in the name.