How to use variables on this Windows batch file
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
add a comment |
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
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 beIF %lngf%==en.srt SET lng=eng
. . . You need to be sure you set the variable value before theIF
statement evaluates it though.
– Pimp Juice IT
Jan 16 at 20:10
That didn't work.
– G. L.
Jan 17 at 0:00
add a comment |
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
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
windows batch environment-variables
edited Jan 16 at 23:58
jonsca
2,995112539
2,995112539
asked Jan 16 at 17:06
G. L.G. L.
7511
7511
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 beIF %lngf%==en.srt SET lng=eng
. . . You need to be sure you set the variable value before theIF
statement evaluates it though.
– Pimp Juice IT
Jan 16 at 20:10
That didn't work.
– G. L.
Jan 17 at 0:00
add a comment |
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 beIF %lngf%==en.srt SET lng=eng
. . . You need to be sure you set the variable value before theIF
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 theIF
statement evaluates it though.– Pimp Juice IT
Jan 16 at 20:10
That didn't work.
– G. L.
Jan 17 at 0:00