How to use variables on this Windows batch file












2















I'm learning batch script and I made some good progress (little, but enough to help me saving time). Now I'd like to work with variables. I've tried reading about variables and I know how to use %object% and replace it in some simple cases. But I don't have any idea on how to use them with "IF" statements.
What I'm trying to do is replace element %lng% with "eng" when element %lngf% is "en.srt".



IF lngf==en.srt SET lng==eng
IF lngf==es.srt SET lng==spa
FOR /R %%A IN (*.avi *.mp4 *.webm *.ogm *.ogv *.flv) do mkvmerge -o "%%~nA.mkv" "%%~A" --language 0:%lng% "%%~nA.%lngf%" --language 0:%lng% "%%~nA.%lngf%"


**language appears 3 times because I usually have 3 languages for subtitles.



My output is:



mkvmerge -o "vsshort.mkv" "C:UsersAdministratorDesktoppessoaltestsvideo.avi" --language 0:eng "vsshort." --language 0:eng "video."
mkvmerge v30.1.0 ('Forever And More') 64-bit
Erro: The file 'video.' file can't be opened for reading: open file error.


Note: it shows --language 0:eng twice. It should show --language 0:eng and then --language 0:spa.










share|improve this question

























  • When comparing, the double equals (==) is correct. But when setting a variable, only one (=) is needed. And when setting the variable, you don't need the % characters.So the last part of that first line should be ... set lng=eng.

    – Doug Deden
    Jan 16 at 17:50











  • It should be IF %lngf%==en.srt SET lng=eng. . . You need to be sure you set the variable value before the IF statement evaluates it though.

    – Pimp Juice IT
    Jan 16 at 20:10













  • That didn't work.

    – G. L.
    Jan 17 at 0:00
















2















I'm learning batch script and I made some good progress (little, but enough to help me saving time). Now I'd like to work with variables. I've tried reading about variables and I know how to use %object% and replace it in some simple cases. But I don't have any idea on how to use them with "IF" statements.
What I'm trying to do is replace element %lng% with "eng" when element %lngf% is "en.srt".



IF lngf==en.srt SET lng==eng
IF lngf==es.srt SET lng==spa
FOR /R %%A IN (*.avi *.mp4 *.webm *.ogm *.ogv *.flv) do mkvmerge -o "%%~nA.mkv" "%%~A" --language 0:%lng% "%%~nA.%lngf%" --language 0:%lng% "%%~nA.%lngf%"


**language appears 3 times because I usually have 3 languages for subtitles.



My output is:



mkvmerge -o "vsshort.mkv" "C:UsersAdministratorDesktoppessoaltestsvideo.avi" --language 0:eng "vsshort." --language 0:eng "video."
mkvmerge v30.1.0 ('Forever And More') 64-bit
Erro: The file 'video.' file can't be opened for reading: open file error.


Note: it shows --language 0:eng twice. It should show --language 0:eng and then --language 0:spa.










share|improve this question

























  • When comparing, the double equals (==) is correct. But when setting a variable, only one (=) is needed. And when setting the variable, you don't need the % characters.So the last part of that first line should be ... set lng=eng.

    – Doug Deden
    Jan 16 at 17:50











  • It should be IF %lngf%==en.srt SET lng=eng. . . You need to be sure you set the variable value before the IF statement evaluates it though.

    – Pimp Juice IT
    Jan 16 at 20:10













  • That didn't work.

    – G. L.
    Jan 17 at 0:00














2












2








2








I'm learning batch script and I made some good progress (little, but enough to help me saving time). Now I'd like to work with variables. I've tried reading about variables and I know how to use %object% and replace it in some simple cases. But I don't have any idea on how to use them with "IF" statements.
What I'm trying to do is replace element %lng% with "eng" when element %lngf% is "en.srt".



IF lngf==en.srt SET lng==eng
IF lngf==es.srt SET lng==spa
FOR /R %%A IN (*.avi *.mp4 *.webm *.ogm *.ogv *.flv) do mkvmerge -o "%%~nA.mkv" "%%~A" --language 0:%lng% "%%~nA.%lngf%" --language 0:%lng% "%%~nA.%lngf%"


**language appears 3 times because I usually have 3 languages for subtitles.



My output is:



mkvmerge -o "vsshort.mkv" "C:UsersAdministratorDesktoppessoaltestsvideo.avi" --language 0:eng "vsshort." --language 0:eng "video."
mkvmerge v30.1.0 ('Forever And More') 64-bit
Erro: The file 'video.' file can't be opened for reading: open file error.


Note: it shows --language 0:eng twice. It should show --language 0:eng and then --language 0:spa.










share|improve this question
















I'm learning batch script and I made some good progress (little, but enough to help me saving time). Now I'd like to work with variables. I've tried reading about variables and I know how to use %object% and replace it in some simple cases. But I don't have any idea on how to use them with "IF" statements.
What I'm trying to do is replace element %lng% with "eng" when element %lngf% is "en.srt".



IF lngf==en.srt SET lng==eng
IF lngf==es.srt SET lng==spa
FOR /R %%A IN (*.avi *.mp4 *.webm *.ogm *.ogv *.flv) do mkvmerge -o "%%~nA.mkv" "%%~A" --language 0:%lng% "%%~nA.%lngf%" --language 0:%lng% "%%~nA.%lngf%"


**language appears 3 times because I usually have 3 languages for subtitles.



My output is:



mkvmerge -o "vsshort.mkv" "C:UsersAdministratorDesktoppessoaltestsvideo.avi" --language 0:eng "vsshort." --language 0:eng "video."
mkvmerge v30.1.0 ('Forever And More') 64-bit
Erro: The file 'video.' file can't be opened for reading: open file error.


Note: it shows --language 0:eng twice. It should show --language 0:eng and then --language 0:spa.







windows batch environment-variables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 16 at 23:58









jonsca

3,030112539




3,030112539










asked Jan 16 at 17:06









G. L.G. L.

7311




7311













  • When comparing, the double equals (==) is correct. But when setting a variable, only one (=) is needed. And when setting the variable, you don't need the % characters.So the last part of that first line should be ... set lng=eng.

    – Doug Deden
    Jan 16 at 17:50











  • It should be IF %lngf%==en.srt SET lng=eng. . . You need to be sure you set the variable value before the IF statement evaluates it though.

    – Pimp Juice IT
    Jan 16 at 20:10













  • That didn't work.

    – G. L.
    Jan 17 at 0:00



















  • When comparing, the double equals (==) is correct. But when setting a variable, only one (=) is needed. And when setting the variable, you don't need the % characters.So the last part of that first line should be ... set lng=eng.

    – Doug Deden
    Jan 16 at 17:50











  • It should be IF %lngf%==en.srt SET lng=eng. . . You need to be sure you set the variable value before the IF statement evaluates it though.

    – Pimp Juice IT
    Jan 16 at 20:10













  • That didn't work.

    – G. L.
    Jan 17 at 0:00

















When comparing, the double equals (==) is correct. But when setting a variable, only one (=) is needed. And when setting the variable, you don't need the % characters.So the last part of that first line should be ... set lng=eng.

– Doug Deden
Jan 16 at 17:50





When comparing, the double equals (==) is correct. But when setting a variable, only one (=) is needed. And when setting the variable, you don't need the % characters.So the last part of that first line should be ... set lng=eng.

– Doug Deden
Jan 16 at 17:50













It should be IF %lngf%==en.srt SET lng=eng. . . You need to be sure you set the variable value before the IF statement evaluates it though.

– Pimp Juice IT
Jan 16 at 20:10







It should be IF %lngf%==en.srt SET lng=eng. . . You need to be sure you set the variable value before the IF statement evaluates it though.

– Pimp Juice IT
Jan 16 at 20:10















That didn't work.

– G. L.
Jan 17 at 0:00





That didn't work.

– G. L.
Jan 17 at 0:00










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1395034%2fhow-to-use-variables-on-this-windows-batch-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1395034%2fhow-to-use-variables-on-this-windows-batch-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Сан-Квентин

8-я гвардейская общевойсковая армия

Алькесар