Search code examples
powershellbatch-filecmdfilenamesbatch-delete

Batch script to remove files with sequential numbers in filename upto certain number


I have list of like 100 or so episodes of a serial whose names are in typical series-episode format with their subtitles named the same way like below:

S01E01.mkv
S01E02.mkv
S01E03.mkv
.....
.....
S01E01.srt
S01E02.srt
S01E03.srt

Now the Video files could be of type MKV or MP4(.mp4) and Subtitles could be of type SRT or VTT(.vtt).

I have such 100 files as I said earlier and I have watched upto 65 episodes so, I want to make a batch script that could let me delete all episodes upto(and including) S01E65 episode Videos and Subtitles(mp4, mkv, srt, vtt).

Unfortunately, I am not so well-versed in Batch to use Regex for finding and deleting operations like these, I know there's for loop and findstr method but I can't wrap my head around a workable solution. Anyone up for assisting ?

Preferred method is definitely Batch, but if it has low feasibility then could switch to Powershell as last resort.


Solution

  • Here's a batch-file example with absolutely no explanation, (due to your lack of shown effort):

    @Echo Off
    SetLocal EnableExtensions
    PushD "V:\ideos\Dir"
    For /F "Delims=" %%G In ('Dir "S01E*.srt" "S01E*.vtt" "S01E*.mp4" "S01E*.mkv" /B
     /A:-D 2^>NUL ^| %SystemRoot%\System32\findstr.exe /R /C:"^S01E0[0123456789]\."
     /C:"^S01E[12345][0123456789]\." /C:"^S01E6[012345]\."') Do Del /A /F "%%G"
    PopD