Page 1 of 1

Editing a variable (Searching from end)

Posted: 14 Apr 2023 11:19
by Vonsworld
Hello

I am trying to perfect a batch file that uses FFMpeg to convert videos to MP3's.

As an example the title of the video might be something like

David Bowie - Life on Mars.mp4
or maybe
David Bowie - Greatest Hits - Life on Mars.mp4

I'd like to extract the track title "Life on Mars" from these filenames to create ID tags in the MP3 file and have loaded the filename into a variable like %filename%.

Please could you suggest some code that would edit %filename% to give the desired result?

Basically I need to search backwards from the end of the string until I encounter the first "<Hypen><Space>" and only save the text that comes afterwards in %filename%.

Thanks
Robin

Re: Editing a variable (Searching from end)

Posted: 14 Apr 2023 22:30
by Aacini
I think this line solve your problem:

Code: Select all

for %%a in ("%filename: - =\%") do set "title=%%~Na"
If you change the <space><hypen><space> by a backslash, then the title takes the place of a file name that can be directly extracted via %%~Na FOR parameter modifier.