@echo off setlocal EnableDelayedExpansion :: --- Configuration --- set "directory=_converted" set "output_format=mp3" set "ffmpeg_options=" :: Create the target directory if not exist "%directory%" mkdir "%directory%" echo Starting conversion to .%output_format% in: %CD% if defined ffmpeg_options echo Extra options: %ffmpeg_options% :: Loop through all files in the current directory for %%F in (*) do ( :: Skip if it's a directory (Batch 'for (*)' usually gets files, but safe check) if exist "%%F\" goto :continue :: Skip the script itself (convert.bat) if /i "%%F"=="%~nx0" goto :continue :: Skip files already in the target format (e.g., .mp3) if /i "%%~xF"==".%output_format%" goto :continue :: Construct output filename: %%~nF is name without extension set "output_file=%%~nF.%output_format%" echo Converting: %%F → !output_file! :: Convert file :: Note: In batch, variables inside the loop need ! ! if delayed expansion is on ffmpeg -loglevel quiet -i "%%F" %ffmpeg_options% "%directory%\!output_file!" if %errorlevel% equ 0 ( echo Done: !output_file! ) else ( echo Error: Failed to convert %%F ) :continue ) echo All done. pause