import sys import os import time # Make sure we got a directory if len(sys.argv) < 2: print("Error: Directory not given!") quit() # Get path, files, and creation/modification times path = sys.argv[1] file_filter = sys.argv[2] if len(sys.argv) > 2 else '' files = [[x, os.path.getctime(f'{path}/{x}'), os.path.getmtime(f'{path}/{x}')] for x in os.listdir(path) if x.endswith(file_filter)] # sort by creation time files.sort(key= lambda x: x[1], reverse=True) # print start of table(including headers) print('
Created | Modified | |
---|---|---|
{x[0]} | {x[1]} | {x[2]} |