0

I have a batch script (-> windows batch .bat automatic .m3u playlist creation / update ) to automatically generate playlists. These playlists are saved in a subfolder of the rootdir (see code). So the problem is, that the subfolder is not taken into account in the playlist, so the music files cannot be found. I get

#EXTINF:???,The Realm Of Orzamar
Dragon Age Origins\The Realm Of Orzamar.mp3

I need

#EXTINF:???,The Realm Of Orzamar
../Dragon Age Origins\The Realm Of Orzamar.mp3

And with something like

SET "location='.../' + %%c"

I get

#EXTINF:???,The Realm Of Orzamar
:\music\Dragon Age Origins\The Realm Of Orzamar.mp3

How can I put this .../ string into SET "location=%%c" so it won't be converted to music\ . An absolut path is not quite a solution since the filestructure is placed on a portable drive and should work independant and out of the folder root, so for use on Android devices and on any other device with different absolut full paths. I am unexperienced with batch, just did some very basic stuff so far, I don't really understand this script since I don't know batch syntax.

Thanks in advance.

Code:

CHCP 1252
@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=H:\music"
>"%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 *.m4a *.wma *.flac *.wav') DO >>"%tempfile%a" ECHO(%%~na:2:%%a
) else (
 PUSHD "%rootdir%\%~1"
 FOR /f "delims=" %%a IN ('dir /b /s /a-d *.mp3 *.mp4 *.ogg *.m4a *.wma *.flac *.wav') 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
4

1 回答 1

1

自己解决了。我看错线了。

 SET "location=%%c"
 SETLOCAL enabledelayedexpansion
  set "location=!location:~%%b!"
  set "back=../"
  ECHO(!back!!location!

做这项工作。!location:~%%b!删除从完整绝对路径到文件夹根目录的前导字符,所以我只需要在此之后添加我的字符​​串

于 2016-09-26T13:03:35.583 回答