On Error Resume Next wscript.echo "Purging watched TV..." ConvertedExtension = ".mp4" Set FSO = CreateObject("Scripting.FileSystemObject") Set WatchedTV = FSO.GetFolder("D:\TV\Watched") Set ConvertedTV = FSO.GetFolder("\\MEDIACENTER\Converted TV") RecordedTVPath = "\\MEDIACENTER\Recorded TV" For Each ConvertedFile In WatchedTV.Files WTVFileName = Replace(Mid(ConvertedFile.Name, InstrRev(ConvertedFile.Name, " ;") + 2), ConvertedExtension, ".wtv") wscript.echo "Purging: " & WTVFileName FSO.DeleteFile RecordedTVPath & "\" & WTVFileName For Each ShowFolder In ConvertedTV.SubFolders If FSO.FileExists(ShowFolder.Path & "\" & ConvertedFile.Name) Then wscript.echo "Purging: " & ShowFolder.Path & "\" & ConvertedFile.Name FSO.DeleteFile ShowFolder.Path & "\" & ConvertedFile.Name End If Next ConvertedFile.Delete Next For Each ShowFolder In ConvertedTV.SubFolders i = 0 For Each ShowFile In ShowFolder.Files If Instr(ShowFile.Name, ConvertedExtension) > 0 Then i = i + 1 If Instr(ShowFile.Name, ";") > 0 Then If Not FSO.FileExists(RecordedTVPath & "\" & Replace(Mid(ShowFile.Name, InstrRev(ShowFile.Name, " ;") + 2), ConvertedExtension, ".wtv")) Then i = i - 1 wscript.echo "Deleting orphaned converted TV: " & ShowFile.Name FSO.DeleteFile ShowFile.Path End If End If End If Next If i = 0 Then wscript.echo "Deleting empty folder: " & ShowFolder.Path ShowFolder.Delete End If Next