0

I am trying to create a little script to convert video on windows using the 'send to' menu. For this I want to create a new file name from the one in input. But I fail to concatenate strings.

Following the syntax found here, I wrote this piece of code:

@echo Input:
@echo %1
set "outputfile=%1%.MP4"
@echo %outputfile%

But I have an issue with the quotes in the outputfile:

Input:
"D:\this is a test\MVI_7754.AVI"

D:\this is a test>set "outputfile="D:\this is a test\MVI_7754.AVI".MP4"
"D:\this is a test\MVI_7754.AVI".MP4

I would expect the extension inside the quotes not outside!

Could someone tell me how I can concatenate the file name and the extension? Thanks!

1 Answer 1

3
@echo Input:
@echo %1
set outputfile="%~1.MP4"
@echo %outputfile%

to remove previous extension use

set outputfile="%~n1.MP4"

if you don't use path names or

set outputfile="%~dpn1.MP4"

(name will be converted to full path)

Sign up to request clarification or add additional context in comments.

5 Comments

BTW, is there is simple way to change the extension of the input file. The best solution for me would be to have in outputfile the string composed of the filename of %1 without its original extension. Thanks!
corrected my answer to accomodate that. also, the first variant should be much simpler.
Thank you again! I took the last one since I need the path. I am used to Unix shells and I wouldn't expect Dos to be so different. Indeed with the first command you gave me set "outputfile=%fname:"=%.MP4", I needed to pass the variable to VLC between "". With the last set outputfile="%~dpn1.MP4" I don't need them. I don't want to bother you too much, but if you could point me a website describing this kind of syntax, I would be eager to learn fishing ;)!
You don't need a website, you need help set and help for commands.
I just had a look at the documentation and as you said that's what I was missing. This will be very helpful in the future. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.