@echo off setlocal EnableExtensions if "%~1"=="" goto usage set "SRC=%~f1" if not exist "%SRC%\" goto usage if "%~2"=="" ( set "LIST=%SRC%\playlist.m3u8" ) else ( set "LIST=%~f2" ) if exist "%LIST%" ( echo Playlist already exists: %LIST% exit /b 1 ) set "FOUND=0" pushd "%SRC%" || exit /b 1 ( echo #EXTM3U for %%E in (mp3 wav flac ogg oga m4a aac opus) do ( for %%F in (*.%%E) do ( if exist "%%~fF" ( echo %%~nxF set "FOUND=1" ) ) ) ) > "%LIST%" set "RESULT=%ERRORLEVEL%" popd if not "%RESULT%"=="0" ( echo Failed to write playlist. exit /b 1 ) if not exist "%LIST%" ( echo Failed to write playlist. exit /b 1 ) if "%FOUND%"=="0" ( echo No audio files found. del "%LIST%" >nul 2>nul exit /b 1 ) echo Playlist created: %LIST% exit /b 0 :usage echo Usage: %~nx0 "music folder" ["playlist path"] exit /b 2