batch-filem3u

Batch for multiple m3u files


I am using this batch file to create .m3u playlists but it creates in a single playlist

@echo on
color 0e
echo PLEASE WAIT, BUILDING PLAYLIST FILE, EXCLUDING BAT, TXT, M3U, SRT and JPG FILES
if exist "playlist.m3u" del "playlist.m3u"
Setlocal EnableDelayedExpansion
set "_t0=1"
if "%CD%"=="%CD:~0,3%" set "_t0=0"
for /F "tokens=*" %%A In ('dir %* /a-d /b /on /s ^| %SystemRoot%\System32\findstr.exe /V /I /E /L ".bat .m3u .txt .db .srt .jpg" ^| %SystemRoot%\System32\sort.exe') do (
    set "_t1=%%A"
    set "_t2=!_t1:%CD%=!"
    echo !_t2:~%_t0%!>>playlist.m3u
)
endlocal

this batch file got here Windows Batch Files and "&"

Folder structure with files, example:

20000 Lieus sous les Mers (1988)(Coktel Vision)
      20000 Lieus sous les Mers (1988)(Coktel Vision)(fr)(Disk 1 of 2)[CPM Version].dsk
      20000 Lieus sous les Mers (1988)(Coktel Vision)(fr)(Disk 2 of 2)[CPM Version].dsk
Zombi (1990)(Ubisoft)
      Zombi (1990)(Ubisoft)(fr)(Disk 2 of 2).dsk
      Zombi (1990)(Ubisoft)(fr)(Disk 2 of 2).dsk

...etc

Example script output (playlist.m3u):

20000 Lieus sous les Mers (1988)(Coktel Vision)\20000 Lieus sous les Mers (1988)(Coktel Vision)(fr)(Disk 1 of 2)[CPM Version].dsk
20000 Lieus sous les Mers (1988)(Coktel Vision)\20000 Lieus sous les Mers (1988)(Coktel Vision)(fr)(Disk 2 of 2)[CPM Version].dsk
Zombi (1990)(Ubisoft)\Zombi (1990)(Ubisoft)(fr)(Disk 2 of 2).dsk
Zombi (1990)(Ubisoft)\Zombi (1990)(Ubisoft)(fr)(Disk 2 of 2).dsk

etc...

I would like to adapt the batch so that it creates multiples m3u according to the name of the folders, example of playlists:

Folders:

20000 Lieus sous les Mers (1988)(Coktel Vision)
Zombi (1990)(Ubisoft)

etc ...

the batch file would create the m3u playlists

20000 Lieus sous les Mers (1988)(Coktel Vision).m3u

/20000 Lieus sous les Mers (1988)(Coktel Vision)/20000 Lieus sous les Mers (1988)(Coktel Vision)(fr)(Disk 1 of 2)[CPM Version].dsk
/20000 Lieus sous les Mers (1988)(Coktel Vision)/20000 Lieus sous les Mers (1988)(Coktel Vision)(fr)(Disk 2 of 2)[CPM Version].dsk

Zombi (1990)(Ubisoft).m3u

/Zombi (1990)(Ubisoft)/Zombi (1990)(Ubisoft)(fr)(Disk 2 of 2).dsk
/Zombi (1990)(Ubisoft)/Zombi (1990)(Ubisoft)(fr)(Disk 2 of 2).dsk

can you help me?


Solution

  • @echo off
    
    for /d %%A in (*) do @if exist "%%~A\*.dsk" (
        for %%B in ("%%~A\*.dsk") do @echo \%%~A\%%~nxB
    ) > "%%~fA\%%~nxA.m3u"
    

    This script is setup to run in the current working directory of where the subfolders are located.

    for /d will get the subfolders. The if exist ensures that *.dsk files exist before writing a .m3u file. for iterates the .dsk files and echoes the path to the .m3u file.

    View for /? about use of modifiers fnx i.e. %%~fA is full path and %%~nxA is name and extension.

    The original code looks unsuitable for the task so did code rewrite, not a code adaption.