Editing a variable (Searching from end)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Vonsworld
Posts: 1
Joined: 14 Apr 2023 11:07

Editing a variable (Searching from end)

#1 Post by Vonsworld » 14 Apr 2023 11:19

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

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Editing a variable (Searching from end)

#2 Post by Aacini » 14 Apr 2023 22:30

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.

Post Reply