# filter the tracking data by grid
import os


def iterate_file(path, files):
    for file in os.listdir(path):
        if ".txt" in file :
            files.append(file)
    files.sort()


def iterate_file_s(path, files, s):
    for file in os.listdir(path):
        if s in file and file.endswith(s):
            files.append(file)
    files.sort()


def check_save_path(save_path):
    if not os.path.exists(save_path+'/'):
        os.makedirs(save_path+'/')


def check_save_path_img(save_path):
    if not os.path.exists(save_path+'image_0\\'):
        os.makedirs(save_path + "\\image_0\\")
        os.makedirs(save_path + "\\image_1\\")


def iterate_file_reverse(path, files):
    for file in os.listdir(path):
        if ".txt" in file :
            files.append(file)
    files.sort(reverse=True)