Domanda

My simple code:

from ftplib import FTP

connect = FTP('pompompom')
connect.login("pompompom")

connect.retrlines('LIST')

This gets me a list of all the folders and files in my directory. I'm trying to have them sorted by the last modified date, the problem is that some of my output looks like this.

drwxr-xr-x    2 1035     1005         4096 Jan 17  2013 test
drwxr-xr-x    2 1035     1005         4096 Dec 31 22:21 test2
drwxr-xr-x    2 1035     1005         4096 Jan 05  2013 test3

So while most entries give me a year, month and day, some give me a month, day and hh:mm instead. How do I get the year for those? (And, if possible, the hh:mm for the others?)

È stato utile?

Soluzione

In absence of year, you may consider it as current year. Subtract one in case the date is in future.

e.g. Current date 14 Feb 2014.

Jan 17 - Year is 2014 Dec 31 - Consider year as 2014. Since, it is future date, subtract 1. Year becomes 2013.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top