Created
October 9, 2019 03:09
-
-
Save kodybrown/b703b778b75b219a29356082d6f8cde6 to your computer and use it in GitHub Desktop.
Launch random .URL file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@setlocal EnableDelayedExpansion | |
@echo off | |
set "SourceDir=." | |
REM count the number of files | |
pushd "!SourceDir!" | |
set /a FileCount=0 | |
for /f "usebackq delims=|" %%I in (`dir /a-d-s-h /b *.url`) do set /a FileCount+=1 | |
popd | |
REM echo .url file count = !FileCount! | |
REM pick a random number | |
call :GetRandumNumber !FileCount! | |
REM echo random number = !RandomNumber! | |
REM pick the file | |
pushd "!SourceDir!" | |
set /a FileCount=0 | |
for /f "usebackq delims=|" %%I in (`dir /a-d-s-h /b *.url`) do ( | |
set /a FileCount+=1 | |
REM echo current file # = !FileCount! | |
REM echo random file = %%I | |
REM if !FileCount! equ !RandomNumber! echo launching: %%I & start "" "%%I" | |
if !FileCount! equ !RandomNumber! echo launching: %%I | |
) | |
popd | |
@endlocal & exit /b | |
:GetRandumNumber MAX | |
REM for some reason this doesn't seem to work, unless I call it twice.. | |
set /a RandomNumber=(%RANDOM% * 100) / 32768 + 1 | |
set /a RandomNumber=(%RANDOM% * %~1) / 32768 + 1 | |
goto :eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment