Remove files if command not sucessful












0















I mux mp4 videos and webm videos with srt (subtitles) files. All the files have the same filenames but different extensions. Like this:



Video1.mp4
Video1.srt


or



Video2.webm
Video2.srt


Sometimes the muxing (merge video with subtitles) is not successful because the srt file is empty. The command line tool I use to merge video with subtitles is called MKVMerge and has 3 exit codes:



0 -- This exit codes means that muxing has completed successfully.



1 -- In this case mkvmerge(1) has output at least one warning, but muxing did continue. A warning is prefixed with the text 'Warning:'. Depending on the issues involved the resulting file might be ok or not. The user is urged to check both the warning and the resulting file.



2 -- This exit code is used after an error occurred. mkvmerge(1) aborts right after outputting the error message. Error messages range from wrong command line arguments over read/write errors to broken files.



I want a command to remove the SRT file if the error code is 1.



Here's what I'm using:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
)


I want that command line to remove the .srt file (which uses the same filename as mp4 or webm) if the error code is 1 (one).










share|improve this question







New contributor




G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Errorlevel - Windows CMD - SS64.com

    – DavidPostill
    Jan 7 at 20:08











  • I know about ERRORLEVEL, but I can only perform simple tasks. I don't know how to append when there's a lot of arguments.

    – G. L.
    Jan 7 at 20:14
















0















I mux mp4 videos and webm videos with srt (subtitles) files. All the files have the same filenames but different extensions. Like this:



Video1.mp4
Video1.srt


or



Video2.webm
Video2.srt


Sometimes the muxing (merge video with subtitles) is not successful because the srt file is empty. The command line tool I use to merge video with subtitles is called MKVMerge and has 3 exit codes:



0 -- This exit codes means that muxing has completed successfully.



1 -- In this case mkvmerge(1) has output at least one warning, but muxing did continue. A warning is prefixed with the text 'Warning:'. Depending on the issues involved the resulting file might be ok or not. The user is urged to check both the warning and the resulting file.



2 -- This exit code is used after an error occurred. mkvmerge(1) aborts right after outputting the error message. Error messages range from wrong command line arguments over read/write errors to broken files.



I want a command to remove the SRT file if the error code is 1.



Here's what I'm using:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
)


I want that command line to remove the .srt file (which uses the same filename as mp4 or webm) if the error code is 1 (one).










share|improve this question







New contributor




G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Errorlevel - Windows CMD - SS64.com

    – DavidPostill
    Jan 7 at 20:08











  • I know about ERRORLEVEL, but I can only perform simple tasks. I don't know how to append when there's a lot of arguments.

    – G. L.
    Jan 7 at 20:14














0












0








0








I mux mp4 videos and webm videos with srt (subtitles) files. All the files have the same filenames but different extensions. Like this:



Video1.mp4
Video1.srt


or



Video2.webm
Video2.srt


Sometimes the muxing (merge video with subtitles) is not successful because the srt file is empty. The command line tool I use to merge video with subtitles is called MKVMerge and has 3 exit codes:



0 -- This exit codes means that muxing has completed successfully.



1 -- In this case mkvmerge(1) has output at least one warning, but muxing did continue. A warning is prefixed with the text 'Warning:'. Depending on the issues involved the resulting file might be ok or not. The user is urged to check both the warning and the resulting file.



2 -- This exit code is used after an error occurred. mkvmerge(1) aborts right after outputting the error message. Error messages range from wrong command line arguments over read/write errors to broken files.



I want a command to remove the SRT file if the error code is 1.



Here's what I'm using:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
)


I want that command line to remove the .srt file (which uses the same filename as mp4 or webm) if the error code is 1 (one).










share|improve this question







New contributor




G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I mux mp4 videos and webm videos with srt (subtitles) files. All the files have the same filenames but different extensions. Like this:



Video1.mp4
Video1.srt


or



Video2.webm
Video2.srt


Sometimes the muxing (merge video with subtitles) is not successful because the srt file is empty. The command line tool I use to merge video with subtitles is called MKVMerge and has 3 exit codes:



0 -- This exit codes means that muxing has completed successfully.



1 -- In this case mkvmerge(1) has output at least one warning, but muxing did continue. A warning is prefixed with the text 'Warning:'. Depending on the issues involved the resulting file might be ok or not. The user is urged to check both the warning and the resulting file.



2 -- This exit code is used after an error occurred. mkvmerge(1) aborts right after outputting the error message. Error messages range from wrong command line arguments over read/write errors to broken files.



I want a command to remove the SRT file if the error code is 1.



Here's what I'm using:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
)


I want that command line to remove the .srt file (which uses the same filename as mp4 or webm) if the error code is 1 (one).







windows command-line video batch






share|improve this question







New contributor




G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Jan 7 at 19:46









G. L.G. L.

358




358




New contributor




G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






G. L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Errorlevel - Windows CMD - SS64.com

    – DavidPostill
    Jan 7 at 20:08











  • I know about ERRORLEVEL, but I can only perform simple tasks. I don't know how to append when there's a lot of arguments.

    – G. L.
    Jan 7 at 20:14



















  • Errorlevel - Windows CMD - SS64.com

    – DavidPostill
    Jan 7 at 20:08











  • I know about ERRORLEVEL, but I can only perform simple tasks. I don't know how to append when there's a lot of arguments.

    – G. L.
    Jan 7 at 20:14

















Errorlevel - Windows CMD - SS64.com

– DavidPostill
Jan 7 at 20:08





Errorlevel - Windows CMD - SS64.com

– DavidPostill
Jan 7 at 20:08













I know about ERRORLEVEL, but I can only perform simple tasks. I don't know how to append when there's a lot of arguments.

– G. L.
Jan 7 at 20:14





I know about ERRORLEVEL, but I can only perform simple tasks. I don't know how to append when there's a lot of arguments.

– G. L.
Jan 7 at 20:14










1 Answer
1






active

oldest

votes


















1














I want that command line to remove the .srt file if the error code is 1.



Look at the error level set by mkvmerge.



Try the following batch file:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
if %errorlevel% equ 1 (
del /q "%%~nA.srt"
)
)




Further Reading




  • An A-Z Index of the Windows CMD command line | SS64.com

  • Windows CMD Commands (categorized) - Windows CMD - SS64.com

  • Del - Delete Files - Windows CMD - SS64.com

  • Errorlevel - Windows CMD - SS64.com






share|improve this answer
























  • Thanks a lot. That's just what I wanted.

    – G. L.
    Jan 7 at 23:27











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
});


}
});






G. L. is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1391631%2fremove-files-if-command-not-sucessful%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I want that command line to remove the .srt file if the error code is 1.



Look at the error level set by mkvmerge.



Try the following batch file:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
if %errorlevel% equ 1 (
del /q "%%~nA.srt"
)
)




Further Reading




  • An A-Z Index of the Windows CMD command line | SS64.com

  • Windows CMD Commands (categorized) - Windows CMD - SS64.com

  • Del - Delete Files - Windows CMD - SS64.com

  • Errorlevel - Windows CMD - SS64.com






share|improve this answer
























  • Thanks a lot. That's just what I wanted.

    – G. L.
    Jan 7 at 23:27
















1














I want that command line to remove the .srt file if the error code is 1.



Look at the error level set by mkvmerge.



Try the following batch file:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
if %errorlevel% equ 1 (
del /q "%%~nA.srt"
)
)




Further Reading




  • An A-Z Index of the Windows CMD command line | SS64.com

  • Windows CMD Commands (categorized) - Windows CMD - SS64.com

  • Del - Delete Files - Windows CMD - SS64.com

  • Errorlevel - Windows CMD - SS64.com






share|improve this answer
























  • Thanks a lot. That's just what I wanted.

    – G. L.
    Jan 7 at 23:27














1












1








1







I want that command line to remove the .srt file if the error code is 1.



Look at the error level set by mkvmerge.



Try the following batch file:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
if %errorlevel% equ 1 (
del /q "%%~nA.srt"
)
)




Further Reading




  • An A-Z Index of the Windows CMD command line | SS64.com

  • Windows CMD Commands (categorized) - Windows CMD - SS64.com

  • Del - Delete Files - Windows CMD - SS64.com

  • Errorlevel - Windows CMD - SS64.com






share|improve this answer













I want that command line to remove the .srt file if the error code is 1.



Look at the error level set by mkvmerge.



Try the following batch file:



FOR /R "D:Folder" %%A IN (*.mp4 *.webm) do (
"D:mkvmerge.exe" -o "%%~nxA" "%%~A" --language 0:eng "%%~nA.srt"
if %errorlevel% equ 1 (
del /q "%%~nA.srt"
)
)




Further Reading




  • An A-Z Index of the Windows CMD command line | SS64.com

  • Windows CMD Commands (categorized) - Windows CMD - SS64.com

  • Del - Delete Files - Windows CMD - SS64.com

  • Errorlevel - Windows CMD - SS64.com







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 7 at 20:21









DavidPostillDavidPostill

104k25225259




104k25225259













  • Thanks a lot. That's just what I wanted.

    – G. L.
    Jan 7 at 23:27



















  • Thanks a lot. That's just what I wanted.

    – G. L.
    Jan 7 at 23:27

















Thanks a lot. That's just what I wanted.

– G. L.
Jan 7 at 23:27





Thanks a lot. That's just what I wanted.

– G. L.
Jan 7 at 23:27










G. L. is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















G. L. is a new contributor. Be nice, and check out our Code of Conduct.













G. L. is a new contributor. Be nice, and check out our Code of Conduct.












G. L. is a new contributor. Be nice, and check out our Code of Conduct.
















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%2f1391631%2fremove-files-if-command-not-sucessful%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

How to make a Squid Proxy server?

Is this a new Fibonacci Identity?

19世紀