# Script to delete corrupt media files from log generated by:
# https://gist.github.com/Desani/129be27da7d735d7c75192ec1aa96c65#file-scanmedia-ps1
# run ScanMedia.ps1 in same directory as ffmpeg.exe, path to scan as arg

import os       #Enable filesystem functionality
import shutil   #Enable file manipulation
from pathlib import Path

allfiles=[line.strip() for line in open('results2.log')] #Import file list and remove newlines
movedfiles = []

delpath = r'K:\\media\\Media Server No Dupe\\Deleted Media Trashcan\\Movies'

for folderName, subfolders, filenames in os.walk(delpath):
   for filename in filenames:
      movedfiles = [filename]

for file in range(len(allfiles)):
   testfile = allfiles[file-1]
   if 'ERROR: Error found: K:' in testfile:
      before, sep, after = testfile.partition('ERROR: Error found: ')
      try:
         shutil.move(os.path.abspath(after), delpath)
      except:
         pass

