Code: Select all
@ECHO OFF
SET P1=C:\PROGRAMS\WINAMP\WINAMP.EXE
SET FSPEC=*.MP3 *.WAV
REM ----------------------------------------
SetLocal EnableExtensions EnableDelayedExpansion
SET K1=0
FOR %%V IN (%FSPEC%) DO (
SET /A K1=K1+1
)
IF %K1% EQU 0 (
ECHO No files found
GOTO END
)
IF %K1% GEQ 32768 (
ECHO The total number of files must be less than 32768.
PAUSE
GOTO END
)
REM ----------------------------------------
SET N=%K1%
SET /A RND = %RANDOM%
SET /A RND = %RANDOM%
SET /A RND = %RANDOM%
SET /A RND = %RANDOM%
SET /A RND = %RANDOM%
SET /A RND = %RANDOM%
SET /A RND = %RANDOM% * N / 32768 + 1
REM ----------------------------------------
SET K3=0
FOR %%V IN (%FSPEC%) DO (
SET /A K3=!K3!+1
IF !K3! EQU %RND% (
SET ANS="%%V"
START %P1% !ANS!
)
)
:END
!ANS! ruins the filenames with "!"'s, i often use them as a "1st line marker"
how can i correct this?
this batch finds the total number of files and randomly selects the one for winamp to play it.
why so many random's in a batch? because if it is one, a batch only selects the same one.