%1 Quote Problems

Started by Thaum2u, February 02, 2023, 02:29:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Thaum2u

I am trying for a simple batch file that will allow me to drag multiple folders (each containing 1 movie video file and a subtitle file for that movie) and drop onto the batch file, which will then use ffmpeg to combine the subtitle file into the video file, resulting in one video file that now has the subtitles embedded into it, instead of two separate files for each and every movie.

My explanations may be overkill, but I want to make it 100% clear...

Each folder will be named the title of a movie.

     EXAMPLE: The Man With Two Brains [1983]

Inside each folder is an .MP4 video file with the exact same name as the folder, as well as the .MP4 file extension at the end.

     EXAMPLE: The Man With Two Brains [1983].mp4

Also inside of each folder is an .SRT subtitle file with the exact same name as the folder, as well as the .SRT file extension at the end.

     EXAMPLE: The Man With Two Brains [1983].srt

My problem is this...

When you drag a folder onto a batch file, the path and name of that folder now occupies the %1 variable. BUT, it also has quotes around it.  The last quote breaks my batch file from working the way I want it to, and I have not been able to figure out a way around it.

Here is the command I need to execute in the batch file:

ffmpeg -i %1.mp4 -i %1.srt -c copy -c:s mov_text -metadata:s:s:0 language=eng %1_sub.mp4

Let's say the path to the folder is this:  c:\movies\The Man With Two Brains [1983]

That whole path and folder name is now stored in %1 with quotes around it. So now, when I use %1.mp4 or %1.srt (Etc...), there is an end quote that stops it from working. I need to get rid of that end quote somehow.

     EXAMPLE:  Echoing %1.mp4 results in this: "c:\movies\The Man With Two Brains [1983]".mp4
     LIKEWISE: Echoing %1.srt results in this: "c:\movies\The Man With Two Brains [1983]".srt
                     
Hopefully this is extremely easy to deal with, but obviously from all the searching and trial and error, I can't figure it out.

Squashman

Yes. When you use drag and drop the paths are quoted that have spaces in them. Removing quotes is quite easy. It just isn't documented in a command where you would think to look. It is documented in the CALL command. To remove quotes is quite simple.
%~1
But remember that you have to put the quotes back in. They are there for a reason. The space is a command delimiter, so you have to put quotes around paths with spaces.

Sam_Weller

It's also in the FOR help too:

%~I         - expands %I removing any surrounding quotes (")