python - How to go through files in a directory and delete them depending on if the "time" column is less than local time -


i new python , right trying go through directory of 8 "train" text files in which, example 1 says: paris - london 19.10

what want create code (probably sort of loop) automatically go through , delete files in time column less local time. in case, when train has left. want happen when start code. have manage happen when give input try open file, not manage make happen without input given user.

def read_from_file(textfile):     try:         infile = open(textfile + '.txt', 'r')         infotrain = infile.readline().rstrip().split(' ')         localtime = time.asctime(time.localtime(time.time()))         localtime = localtime.split(' ')         if infotrain[2] < localtime[3]:             os.remove(textfile + '.txt')             print('this train has left station.')             return none, none     except:         pass 

(be aware not whole function long , contains code not relate question) have solution?

os.listdir() gives of the file names in directory.

import os file_names = os.listdir(".") fname in file_names:     # time checking stuff here 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -