import os import time name_time_list = [] target_dir = '/home/mc365/data/dummy' while True: time.sleep(60) root_path = "/home/mc365/data/" filenames = os.listdir(root_path) for f in filenames: w_time = os.path.getctime(root_path + f) name_time_list.append((f, w_time)) sorted_list = sorted(name_time_list, key=lambda x: x[1], reverse=True) recent_file = sorted_list[0] tmp_recent = str(root_path) + str(recent_file[0]) if target_dir != tmp_recent: time.sleep(5) command = 'docker run --rm --name mail_recorder --gpus '"device=1"' --privileged -v /dev:/dev -v /home/mc365/sources:/sources -v /home/mc365/data/'+str(recent_file[0])+':/data/'+str(recent_file[0])+' stereolabs/zed:3.5-gl-devel-cuda11.1-ubuntu18.04 python3 /sources/recorder.py.bak' os.system(str(command)) target_dir = str(root_path) + str(recent_file[0])