I have a huge directory with thousand+ files in it
I want to get the files created from 7:30PM to 7:30 AM and vice versa.
I have been using below code to do it but seems its getting slower as files increase. I am running it on Linux.
First I defined get_time function here:
def get_time():
    tmp_date = datetime.now()
    year = tmp_date.year
    month = tmp_date.month
    day = tmp_date.day  
    date_start = datetime(year, month, day, 7,30)
    date_end = datetime(year, month, day, 19,30)
    shift = "Day Shift"
    if (date_start < tmp_date) and (tmp_date > date_end):
        date_start = datetime(year, month, day, 19,30)
        date_end = datetime(year, month, day, 7,30) + timedelta(1)
        shift = "Night Shift"
        
    elif (date_start > tmp_date) and (tmp_date < date_end):
        date_start = datetime(year, month, day, 19,30) - timedelta(1)
        date_end = datetime(year, month, day, 7,30)
        shift = "Night Shift"
    
    return date_start, date_end, shift
and then
def get_qc_success(ROOT_FOLDER):
    date_start, date_end, shift = get_time()
    
    files = []
    ARCHIVE_FOLDER = os.path.join(ROOT_FOLDER,"LOMS","ARCHIVE")
    files = os.listdir(ARCHIVE_FOLDER)
    for csv in os.listdir(ARCHIVE_FOLDER):
        path = os.path.join(ARCHIVE_FOLDER,csv)
        filetime = datetime.fromtimestamp(
                os.path.getctime(path))
        if (date_start < filetime < date_end):
            files.append(csv)
    len_success = len(files)
            
    return files, len_success, shift
Is there any other methods to make it even faster ?
 
     
    
