@ECHO OFF CLS REM CREATE-PLAYLIST.BAT Written by Neil Popham, 2005 (neilpopham@bigfoot.com) SET batchname=CREATE-PLAYLIST.BAT SET version=1.0.2 TITLE=%batchname%, Version %version% REM REM ############################## REM PLEASE CONFIGURE THESE VARIABLES REM REM ############################## REM Set the name of the playlist to create in each folder SET playlist=playlist.m3u REM Create list of valid file extensions SET validExtn=.mp3.mp2.mp1.mpc.mp+.mpp.ogg.aac.mac.ape.flac.fla.wv.shn.ofr.ofs.ogg.m4a.mp4 REM REM ############################## REM Add another delimiter to the end so I can search for .. SET validExtn=%validExtn%. REM Check a folder has been passed IF NOT EXIST %1 GOTO NoParams IF %~z1 GTR 0 GOTO NoParams REM Remove all existing "playlist.m3u" files otherwise files will be appended FOR /R %1 %%G IN (%playlist%) DO IF EXIST %%G DEL "%%G" REM Iterate through every file and pass the path to :WriteToPlayList FOR /R %1 %%G IN (*.*) DO CALL :WriteToPlayList "%%G" GOTO:EOF REM ======================================================================== REM WriteToPlayList : Adds the file to the playlist, if the extension fits REM : %1 The file to process REM ======================================================================== :WriteToPlayList REM Check that the file extension is valid SET extn=%~x1 IF [%extn%] EQU [] GOTO:EOF SET tmpExtn=%validExtn% CALL SET result=%%tmpExtn:%extn%.=%% REM If no match found in list of extensions exit function IF [%result%] EQU [%validExtn%] GOTO:EOF REM Escape ampersand and caret SET tmpString="%~nx1" SET tmpString=%tmpString:^=^^% SET tmpString=%tmpString:&=^^^&% REM Remove quotes SET tmpString=%tmpString:"=% REM Write filename to playlist ECHO %tmpString%>>"%~dp1\%playlist%" GOTO:EOF REM ===================================================== REM NoParams : a folder has not been passed REM ===================================================== :NoParams ECHO To run this script, please pass a folder as a parameter. ECHO. ECHO Press any key to exit PAUSE >NUL REM VERSION HISTORY REM =============== REM Version Date Description REM ================================ REM 1.0.2 12/07/2005 Added parameter check REM 1.0.1 12/07/2005 Original still had some test code in REM 1.0.0 12/07/2005 Initial Version