1.

Solve : Batch file to alter m3u file (Newbie request)?

Answer»

Hi,
I export playlists from iTunes as m3u files, but have to alter them before I can use them in my car's audio system. I currently do this by opening them in Notepad, and using 'replace all' to make the changes but as there are quite a few playlists, this takes some time, and I think there must be an easier way. Could a batch file do this for me ?.

The playlists are .m3u files, and have multiple lines of paths to music files like :-

E:\Music\Music Library\song 1.mp3

from which I want to remove the text shown red from each line. Is this possible with a batch file ? (ideally running it once to do all the different playlists). If so, could someone point me in the right direction ?

Ta There is an exact science to batch where it doesn't bend on commands at all. To get the most accurate SCRIPT we would need an example or two of the m3u files. Without them we can only really guess at what needs to be done. Here is a script that should do the job though I would run it on a backup version of your m3u folder just in case.

Code: [Select]@ECHO off
setlocal EnableDelayedExpansion

for /f "delims=" %%A in ('dir /b ^| find ".m3u"') do call :m3u "%%A"

exit /b




:m3u
0>nul set /p=Processing %~1 . . .
set m3u=%~1
for /f "delims=" %%B in (%m3u%) do (
set "WORKING=%%B"
if "!working:~0,9!"=="E:\Music\" set "working=!working:~9!"
echo !working! >>%m3u%.done
)
notepad %~1.done
:: DEL /f "%~1"
:: rename "%~1.done" "%~1"
echo Done.
goto :eof

If the file that it opens up does what you want it to, remove both "::" and the line 'notepad %~1.done'. I hope this helps.Try this:

Code: [Select]@echo off
for /f "delims=" %%a in (' dir *.m3u /b ') do (
echo %%a
call repl "E:\\Music\\" "" im <"%%a" >"%%a.tmp"
move /y "%%a.tmp" "%%a" >nul
)
pause

This uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855Thanks Lemonilla - that worked perfectly !

Thanks also for your response foxidrive - I did try it too, but couldn't get it to work, but that was PROBABLY due to my error.



Discussion

No Comment Found