Python Scripting : Get max Last Modified Date using os.walk


Below is the code that i have written to get the max Lsat Modified Date of the files in all folders that i can delete all the folders that are not not being used by me for a long time.

#-*-coding:utf8;-*-
#qpy:2
#qpy:console
import os
import datetime
print “This is console module”
def comparefiletime(in_file,in_date) :
lastdate =datetime.datetime.fromtimestamp(os.path.getmtime(in_file))
if lastdate > in_date:
return lastdate
else:
return in_date

def getmaxdatefolders(in_root_fldr):
for foldern, sfoldern, filen in os.walk(in_root_fldr):
maxdate = datetime.datetime(1900, 1, 1,00,00)
for fileo in filen:
maxdate = comparefiletime(os.path.join(foldern,fileo),maxdate);
printmax date for the folder %s is %s’ %(foldern, maxdate)

getmaxdatefolders(‘storage/emulated/0/’);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: