@ECHO OFF
SETLOCAL
:: make a tempfile
:maketemp
SET "tempfile=%temp%\%random%"
IF EXIST "%tempfile%*" (GOTO maketemp) ELSE (ECHO.>"%tempfile%a")
:: Need the start of the tree to scan
SET "rootdir=c:\sourcedir"
>"%tempfile%b" (ECHO(%rootdir%&ECHO(*)
FOR /f "delims=:" %%a IN ('FINDSTR /o /L "*" "%tempfile%b"') DO SET /a len=%%a-1
SET "destfile=%~1"
:loop
SHIFT
SET nextdir=%~1
IF NOT DEFINED nextdir GOTO process
PUSHD "%rootdir%\%~1"
FOR /f "delims=" %%a IN ('dir /b /s /a-d *.mp3 *.mp4 *.ogg') DO >>"%tempfile%a" ECHO(%%~na:%%a
POPD
GOTO loop
:process
>%destfile% ECHO(#EXTM3U
(
FOR /f "tokens=1*delims=:" %%a IN ('SORT "%tempfile%a"') DO (
ECHO(#EXTINF:???,%%a
SET "location=%%b"
SETLOCAL enabledelayedexpansion
ECHO(!location:~%len%!
endlocal
)
)>>%destfile%
DEL "%tempfile%*"
GOTO :EOF
I used c:\sourcedir
as my starting directory. No parameter-validity checks are performed. You'd need to CALL create_m3u.bat
from create_all_playlist.bat
because the target executble is a batch file.
As for the missing data - hardest part is extracting information....
Edited to allow !
in filenames and remove leading \
from path
Revision: To permit absolute path
@ECHO Off
SETLOCAL
:: make a tempfile
:maketemp
SET "tempfile=%temp%\%random%"
IF EXIST "%tempfile%*" (GOTO maketemp) ELSE (ECHO.>"%tempfile%a")
:: Need the start of the tree to scan
SET "rootdir=c:\sourcedir"
>"%tempfile%b" (ECHO(%rootdir%&ECHO(*)
FOR /f "delims=:" %%a IN ('FINDSTR /o /L "*" "%tempfile%b"') DO SET /a len=%%a-1
SET "destfile=%~1"
:loop
SHIFT
SET nextdir=%~1
IF NOT DEFINED nextdir GOTO process
IF %nextdir:~0,1%==\ (
PUSHD "%~1"
FOR /f "delims=" %%a IN ('dir /b /s /a-d *.mp3 *.mp4 *.ogg') DO >>"%tempfile%a" ECHO(%%~na:2:%%a
) else (
PUSHD "%rootdir%\%~1"
FOR /f "delims=" %%a IN ('dir /b /s /a-d *.mp3 *.mp4 *.ogg') DO >>"%tempfile%a" ECHO(%%~na:%len%:%%a
)
POPD
GOTO loop
:process
>%destfile% ECHO(#EXTM3U
(
FOR /f "tokens=1,2*delims=:" %%a IN ('SORT "%tempfile%a"') DO (
ECHO(#EXTINF:???,%%a
SET "location=%%c"
SETLOCAL enabledelayedexpansion
ECHO(!location:~%%b!
endlocal
)
)>>%destfile%
del "%tempfile%*"
GOTO :EOF
Noting that "paths containing spaces must be in quotes"