So this weekend, I decided to scratch my own itch and figure out a way to play a random media file. Let’s say you’ve got a lot of tv shows or movies and you don’t want to browse… you want to channel surf. This is how you can do it in Windows:
chcp 65001
setlocal EnableDelayedExpansion
set count=0
for /f "delims=" %%a in ('dir /b /s *.avi *.mkv *.mp4 *.mov *.wmv') do @(
set filename[!count!]=%%a
set /a count = count + 1
)
:loop
set /a choose = (%random% * 32768 + %random%) %% count
set chosen=!filename[%choose%]!
start "Opening %chosen%" "%chosen%"
pause
goto loop
Thanks to all the random stack overflow posts I had to go through. And metafilter for actually having something useful. This isn’t the cleanest code, but it mostly works for me right now. I still have unicode problems, even with chcp 65001
. Maybe I can access files by their 8.3 filename.