Random Subset of Music

Do you have a too large collection of music to fit on your portable device?

Is it hard too decide which songs to copy over?

 

Worry not, I have the bat file for you.

 

It will select a set of 500 songs randomly selected from any of the mp3/m4a files in the given directory.

It can sometimes select the same song twice, so it practice its more like 496 or something. I have been using this for like 2 years now, but now its recorded.

Every 3 months or so I regenerate the list and copy it to my phone so i have a new random selection for the hour commute.

 

I run it on 70GB (13237 songs), on a normal desktop, 7200rpm hard drive and it takes about 40 seconds.

Although the script does fetch every file and then select a random selection, so it may look like its doing nothing for a while.

Script here:

@echo off&setlocal enabledelayedexpansion
set "musicroot=S:\murph\Music\All Music"
set "playfolder=S:\murph\Music\Out"
set /a filecount=500

pushd "%musicroot%"
for /r %%i in (*.mp3) do set /a files+=1& set "$!files!=%%~i"
for /r %%i in (*.m4a) do set /a files+=1& set "$!files!=%%~i"
popd
pushd "%playfolder%"
:randomloop
set /a rd=%random%%%files+1
set "mp3=!$%rd%!"
if not defined mp3 goto :randomloop
set "$%rd%="
for %%i in ("%mp3%") do if exist "%%~nxi" echo "%%~nxi" already exist in %playfolder%.& goto:randomloop
copy "%mp3%"
set /a filecount-=1
if %filecount% gtr 0 goto:randomloop
popd

Give me an email (mine is on the main site) if you care so I can attribute it.