@echo off SETLOCAL EnableExtensions EnableDelayedExpansion REM change to directory of dragged files pushd "%~dp1" REM Include paths for external programs set path="F:\Utilities\commandlinetools\Mp3wrap";%path% set path="F:\Utilities\commandlinetools\id3";%path% set path="F:\Utilities\MP3Val";%path% REM mergeMP3_cects.bat REM Place this file anywhere and drag and drop two or more mp3 files to merge them REM ------------------ Version History ---------------------------------- REM Add new line for updated versions, keep previous for record REM XX.XXX YYYY-MM-DD Author Description SET version=01.000 2015-03-13 cects.com initial version SET version=01.001 2015-03-14 cects.com blog version REM -------------------------- Set title -------------------------------- REM note: "%~nx0" = filename of the batch file SET title=%~nx0 - version %version% TITLE %title% REM Optional - use to check for an argument or drag and drop. Change the REM code below as required REM if "%1" == "" call :xxx & exit /b 1 REM ----------------------------- Program Code -------------------------- echo Current working directory (%%CD%%): %CD% echo Directory of this script (%%~dp0): %~dp0 :main goto begin REM check to see if this file was executed without dragging a file to it :begin if [%1]==[] ( echo. echo "no files dragged to this file. Try again." echo. echo "press any key to exit ...." echo. pause >nul goto end ) else ( rem set variable file1. This will be used for tagging the merged file set file1=%~nx1 ) call:theorder %* call:ask %* rem call:processmp3win %* rem call:processmp3 %* call:metadatafix call:mp3validate call:renamefile goto done REM ----------------------------- Program Code End ---------------------- :done echo. echo "Files joined successfully" echo. echo. call:errorfunc echo. REM Note: Endlocal causes Title to not display on exit, but REM countdown will display Endlocal REM ---------------------- Delayed Exit ------------------------------------ REM Sets exit code to 0 echo exiting in 15 seconds..........&echo. echo hit PAUSE on keyboard to pause... any key will resume exit FOR /l %%a in (15,-1,1) do (TITLE %title% -- closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL) Title Press any key to exit . . .&echo.&EXIT REM --------------------- Function Section ----------------------------------- :errorfunc echo The exit error code is: %ERRORLEVEL% goto :eof :theorder echo. echo Files will be processed in this order: echo. for %%z in (%*) do ( echo %%z ) echo. rem echo Press any key to continue merging files, or close window to start over .... rem pause >nul goto :eof REM Use Setlocal Endlocal for function so file1 can be used to rename file :processmp3win SETLOCAL set index=1 for %%t in (%*) do ( rem echo %%t set file!index!=%%t if not !file1!==%%t ( set file1=!file1!+%%t ) set /A index+=1 ) echo. echo Combined mp3file: echo !file1! echo. echo copying the following files to "temp_MP3WRAP.mp3" copy /b !file1! "temp_MP3WRAP.mp3" echo. Endlocal goto :eof :processmp3 REM merge dragged and dropped files with mp3wrap echo. mp3wrap temp.mp3 %* echo. echo "Merge complete" echo. echo. goto:eof :metadatafix REM copy tags from first file to merged file with id3 rem id3.exe -D %file1% -1 -2 "temp_MP3WRAP.mp3" id3.exe -D %file1% "temp_MP3WRAP.mp3" echo. echo "Metadata copied" echo. echo. echo. goto:eof :mp3validate REM fix errors of merged file with mp3val mp3val temp_MP3WRAP.mp3 -f -nb -si echo. echo "Errors repaired" echo. goto:eof :renamefile set name="%file1:~0,-4%_merged.mp3" ren "*MP3WRAP.mp3" %name% echo "Temp file renamed to %name%" goto:eof :ask set INPUT= set /p INPUT=Process files with Windows (W) or with MP3Wrap (M): if not defined INPUT goto ask if /i "%INPUT:"=%"=="w" call:processmp3win %* && goto :eof if /i "%INPUT:"=%"=="m" call:processmp3 %* && goto :eof echo Incorrect input, try again & goto ask goto :eof REM --------------------------- exit ----------------------------------------- :end EXIT