I need help to split a file name or folder name into two parts.
All files in the subfolders use always the same naming convention:
mainfolder/artist - title/artist - title.ext
I started with creating a batch file which writes .nfo files (recursive) for video files. Everything is working fine, but I just can't find a way to echoing the part1 (artist) before delimiter - and after it to have part2 (title).
Here is what I have now:
@echo off
TITLE NFO creator Musicvideos
COLOR B
ECHO -------------------------------------------------------------------------
ECHO Create NFO for Musicvideos, all existing will be overwritten
ECHO Push key to Start
ECHO -------------------------------------------------------------------------
ECHO.
PAUSE > NUL
REM Ende Header
for /r %%a in (*.mkv *.avi *.mp4) do (
(
echo ^<?xml version="1.0" encoding="UTF-8" standalone="yes"?^>
echo ^<musicvideo^>
for %%b in ("%%~na") do echo ^ ^<title^>%%~b^</title^>
echo ^ ^<^!-- start test set attributes --^>
for %%b in ("%%~na") do echo ^ ^<path^>%~dp0^</path^>
for %%b in ("%%~na") do echo ^ ^<name^>%%~na^</name^>
for %%b in ("%%~na") do echo ^ ^<filenameandpath^>%%~a^</filenameandpath^>
for %%b in ("%%~na") do echo ^ ^<basepath^>%%~a^</basepath^>
for %%b in ("%%~na") do echo ^ ^<before^>^</before^>
REM for "tokens=1,2 delims= - " %%b in ("%%~na") do (
REM echo ^ ^<before^>^%%a</before^>
REM echo ^ ^<after^>^%%b</after^>
REM )
REM test end
echo ^ ^<rating^>^0.000000^</rating^>
echo ^ ^<userrating^>^8^</userrating^>
echo ^ ^<epbookmark^>^0.000000^</epbookmark^>
echo ^ ^<year^>^</year^>
echo ^ ^<track^>^-1^</track^>
echo ^ ^<album^>^</album^>
echo ^ ^<artist^>^</artist^>
echo ^ ^<genre^>^</genre^>
echo ^ ^<outline^>^</outline^>
echo ^ ^<plot^>^</plot^>
echo ^ ^<tagline^>^</tagline^>
echo ^ ^<thumb^>^</thumb^>
echo ^ ^<status^>^</status^>
echo ^ ^<studio^>^</studio^>
echo ^ ^<art^>
echo ^ ^<fanart^>%~dp0^%%~na^-fanart.jpg^</fanart^>
echo ^ ^<poster^>%~dp0^%%~na^-poster.jpg^</poster^>
echo ^ ^<artistthumb^>%~dp0^%%~na^-artistthumb.jpg^</artistthumb^>
echo ^ ^<banner^>%~dp0^%%~na^-banner.jpg^</banner^>
echo ^ ^<clearlogo^>%~dp0^%%~na^-clearlogo.png^</clearlogo^>
echo ^ ^<discart^>%~dp0^%%~na^-discart.png^</discart^>
echo ^ ^<landscape^>%~dp0^%%~na^-landscape.jpg^</landscape^>
echo ^ ^</art^>
echo ^</musicvideo^>
)>"%%~dpna.nfo"
)
ECHO.
ECHO Creatin is done
ECHO Push key to exit
ECHO.
PAUSE > NUL
This is the way I would do it:
@echo off
setlocal
for /R %%A in (*.mkv *.avi *.mp4) do call :SplitFileName "%%~nA"
goto :EOF
:SplitFileName
set "FileName=%~1"
set "Title=%FileName: - =" & set "Artist=%"
echo Artist=%Artist%
echo Title=%Title%
exit /B
Further details at Split string with string as delimiter. Pay attention to the comment at such an answer...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With