delete command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Anomaly-XB-6783
Posts: 4
Joined: 15 Jan 2016 04:05

delete command

#1 Post by Anomaly-XB-6783 » 15 Jan 2016 04:13

english Version:
Hi, i need an additional command that delete the original files, but not the files that did not match this command:

FOR %%A IN (*.mkv) DO mkvmerge -o "%%~nA (subbed).mkv" "%%~A" "%%~dpnA.srt"
FOR %%A IN (*.mp4) DO mkvmerge -o "%%~nA (subbed).mp4" "%%~A" "%%~dpnA.srt"
FOR %%A IN (*.avi) DO mkvmerge -o "%%~nA (subbed).avi" "%%~A" "%%~dpnA.srt"

This command creates from test.mkv + test.srt the file test.mkv (subbed)
The Following files test1.mkv, test2.mkv,etc. without .srt should not be deleted.

Deutsche Version:
Hi ich würde gerne zu folgenden Kommandos, ein Kommando haben zum löschen der original Dateien haben, allerdings sollen andere Dateien die noch keine .srt Datei nicht gelöscht werden:

FOR %%A IN (*.mkv) DO mkvmerge -o "%%~nA (subbed).mkv" "%%~A" "%%~dpnA.srt"
FOR %%A IN (*.mp4) DO mkvmerge -o "%%~nA (subbed).mp4" "%%~A" "%%~dpnA.srt"
FOR %%A IN (*.avi) DO mkvmerge -o "%%~nA (subbed).avi" "%%~A" "%%~dpnA.srt"

Das Kommando erstellt aus z.b. einer test.mkv + test.srt die Datei test.mkv (subbed)
Die Dateien test1.mkv, test2.mkv, usw. ohne .srt Dateien sollen aber nicht gelöscht werden.
Ich möchte quasi die quell Dateien löschen und nur die test.mkv (subbed) Dateien behalten, aber wenn andere Dateien ohne .srt Datei im Ordner sind sollen diese nicht gelöscht werden.

THX
Anomaly-XB-6783

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: delete command

#2 Post by foxidrive » 15 Jan 2016 06:33

Anomaly-XB-6783 wrote:english Version:
Hi, i need an additional command that delete the original files, but not the files that did not match this command:

FOR %%A IN (*.mkv) DO mkvmerge -o "%%~nA (subbed).mkv" "%%~A" "%%~dpnA.srt"
FOR %%A IN (*.mp4) DO mkvmerge -o "%%~nA (subbed).mp4" "%%~A" "%%~dpnA.srt"
FOR %%A IN (*.avi) DO mkvmerge -o "%%~nA (subbed).avi" "%%~A" "%%~dpnA.srt"

This command creates from test.mkv + test.srt the file test.mkv (subbed)
The Following files test1.mkv, test2.mkv,etc. without .srt should not be deleted.


Which files do you want to delete?

Anomaly-XB-6783
Posts: 4
Joined: 15 Jan 2016 04:05

Re: delete command

#3 Post by Anomaly-XB-6783 » 15 Jan 2016 07:05

hi, i want to delete the "test.mkv" and "test.srt" file, if a "test.mkv (subbed)" is created. If there is a "test1.mkv" file but no ".srt" file, the batch should just skip it (which is the batch currently do, but i don't know if it keep donig it, if there is a delete command.)

Example:
1.
test.mkv + test.srt = test.mkv (subbed)
(delete) (delete) (keep)

2.
test1.mkv
(keep, because there is no test1.srt.)

btw: sorry for my bad english, i can read and understand everything but i can't write very good.

THX

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: delete command

#4 Post by foxidrive » 15 Jan 2016 07:47

Your English is good...

This should solve it - I think the 2nd part means you want to skip the mkvmerge process and keep those files, when there is no corresponding .srt file, and that's what the code below should do.

Code: Select all

@echo off
FOR %%A IN (*.mkv *.mp4 *.avi) DO if exist "%%~dpnA.srt" (
   mkvmerge -o "%%~nA (subbed)%%~xA" "%%~A" "%%~dpnA.srt"
   if exist "%%~nA (subbed)%%~xA" del "%%~A"
)

Anomaly-XB-6783
Posts: 4
Joined: 15 Jan 2016 04:05

Re: delete command

#5 Post by Anomaly-XB-6783 » 16 Jan 2016 01:51

Hi, first of all thanks for your answer. But unfortunately this does not work. When I start the batch it opened up a window and it closed again immediately without doing anything.

greets
Anomaly-XB-6783

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: delete command

#6 Post by foxidrive » 16 Jan 2016 03:15

Try this modification:

Code: Select all

@echo off
FOR %%A IN (*.mkv *.mp4 *.avi) DO echo found "%%a"&if exist "%%~dpnA.srt" (
   echo processing "%%a"
   mkvmerge -o "%%~nA (subbed)%%~xA" "%%~A" "%%~dpnA.srt"
   if exist "%%~nA (subbed)%%~xA" del "%%~A"
)
pause

Anomaly-XB-6783
Posts: 4
Joined: 15 Jan 2016 04:05

Re: delete command

#7 Post by Anomaly-XB-6783 » 16 Jan 2016 03:51

Almost perfect. The video file got deleted but not the .srt file. But I've figured out that I just have to ad "%%~dpnA.srt" at the end and it worked fine. Thank you very very much. I've googled it so long before I found this forum here. Vielen Dank. :-)

the code looks like this now:

Code: Select all

@echo off
FOR %%A IN (*.mkv *.mp4 *.avi) DO echo found "%%a"&if exist "%%~dpnA.srt" (
   echo processing "%%a"
   mkvmerge -o "%%~nA (subbed)%%~xA" "%%~A" "%%~dpnA.srt"
   if exist "%%~nA (subbed)%%~xA" del "%%~A" "%%~dpnA.srt"
)
pause

Post Reply