May-06-2023, 11:42 PM
Hi all,
i wanted to code a Monitor that observes a Folder and it`s subfolders for new mkv and mp4 Files. But when i add a File to the Folder the Routine always shows me all files it has found and not just the new onces.
i tried it with
new_series = [item for item in resseries if item not in old_series]
where new_series should contain only the new files, but i have no idea why it always shows the whole content of old_series once i copy a new file to the folder.
I´ve attached my whole code, maybe someone hass an Idea
i wanted to code a Monitor that observes a Folder and it`s subfolders for new mkv and mp4 Files. But when i add a File to the Folder the Routine always shows me all files it has found and not just the new onces.
i tried it with
new_series = [item for item in resseries if item not in old_series]
where new_series should contain only the new files, but i have no idea why it always shows the whole content of old_series once i copy a new file to the folder.
I´ve attached my whole code, maybe someone hass an Idea
import os,re,time from os import walk from time import sleep import subprocess,os,sys,time from datetime import datetime import requests # folder path dir_pathmovies = r'T:\\latest Movies\\_test\\' dir_pathseries = r'T:\\Series\\test\\' # list to store files result = [] resmovies = [] resseries = [] newmovies = [] newseries = [] old_series = [] old_movies = [] def monitor(): global result,resmovies,resseries,dir_pathmovies,dir_pathseries,old_series,old_movies mkv = [] mp4 = [] # Iterate directory - Initial Setup for (dir_pathseries, dir_names, file_names) in walk(dir_pathseries): result.extend(file_names) mkv = [x for x in result if ".mkv" in x] mp4 = [x for x in result if ".mp4" in x] old_series.append(mkv) old_series.append(mp4) result.clear mkv = [] mp4 = [] for (dir_pathmovies, dir_names, file_names) in walk(dir_pathmovies): result.extend(file_names) mkv = [x for x in result if ".mkv" in x] mp4 = [x for x in result if ".mp4" in x] old_movies.append(mkv) old_movies.append(mp4) try: while True: scanseries() new_series = [item for item in resseries if item not in old_series] print (new_series) old_series=resseries # copy new found names to the old_list for remaining in range(10, 0, -1): sys.stdout.write("\r") sys.stdout.write("{:2d} seconds remaining before new DIRSCAN.".format(remaining)) sys.stdout.flush() time.sleep(1) except KeyboardInterrupt: exit() def scanseries(): global dir_pathseries,dir_pathmovies,resseries resseries = [] result = [] for (dir_pathseries, dir_names, file_names) in walk(dir_pathseries): result.extend(file_names) mkv = [x for x in result if ".mkv" in x] mp4 = [x for x in result if ".mp4" in x] resseries.append(mkv) resseries.append(mp4) # print () # print ("scan") # print (result) def scanovies (): exit monitor()