I'm not sufficient at writing any kind of batch script so I kind of mashed up this solution from elsewhere. It does the job; copies files from a directory (and all it's subdirectories) to another directory, seemingly randomly.
However it doesn't manage to copy the complete amount of files and I'm not sure why. If I set it to 10 it returns maybe 7 or 8. Any ideas? Thanks.
@echo off setlocal :: Create numbered list of files in a temporary file set "tempFile=%temp%\%~nx0_fileList_%time::=.%.txt" dir "D:\Users\...\Music" /b /s /a-d %1 | findstr /n "^" >"%tempFile%" :: Count the files for /f %%N in ('type "%tempFile%" ^| find /c /v ""') do set cnt=%%N :: Copy number random files, doesn't get them all though? for /l %%N in (1 1 100) do call :copyRandomFile :: Delete the temp file del "%tempFile%" exit /b :copyRandomFile set /a "randomNum=(%random% %% cnt) + 1" for /f "tokens=1* delims=:" %%A in ( 'findstr "^%randomNum%:" "%tempFile%"' ) do xcopy "%%B" "D:\Users\...\Playlists\Random" exit /b
Edit: Sorry, to explain further: I have a folder full of music (though sorted in different sub directories based on artists etc) and I want to randomly select 100 of the files and copy them to my output folder, in order to essentially have a 100 song random playlist to transfer onto mp3 player. The code above does this,but for some reason some it doesn't copy the required amount of files.