[Easy question] - list 2 files in dir as old based on date


Assume 6 files are stored in a dir named:
How do I print the 2 newest files as 'new' and rest marked as 'old' based on the date set in the name.

$  ./date_script.py
[old]      file_20120101.tar.gz
[old]      file_20130101.tar.gz
[old]      file_20140101.tar.gz
[old]      file_20141011.tar.gz
[new]    file_20151011.tar.gz
[new]    file_20161011.tar.gz

What modules and approach is required to list items as requested.

I got a start by listing the dirs.

import glob, os
for file in glob.glob("*.tar.gz"):


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.