How to find the most recently modified folder in a directory of directories (python)?
===

I've gave it a decent attempt based on other answers I've found but haven't managed anything solid. Basically, I have a folder called "scratch" where users can create there own folders to dump their data.<br>
I need my script to find out which user's folders haven't been used for over 30 days. I figured I could do this by finding the most recently modified directory in the users folder (by searching it recursively) then filter out ones older.

Code to get a list of users directories:<br>

        dirlist = list()
        for filename in os.listdir("\\\\abg-netapp1\\Scratch\\"):
            dirlist.append(filename)

Then I can iterate over each index of 'dirlist' to create a full path to search:

        x=0
        for item in dirlist:
            max_mtime = 0
            for dirname,subdirs,files in os.walk("\\\\abg-netapp1\\Scratch\\" + dirlist[x]):
                for fname in subdirs:
                    full_path = os.path.join(dirname, fname)
                    mtime = os.stat(full_path).st_mtime
                    if mtime > max_mtime:
                        max_mtime = mtime
                        max_dir = dirname
                        max_file = fname
            print max_dir, max_file, time.strftime('%Y-%m-%d', time.localtime(max_mtime))
            x+=1

I do know I haven't gone about filtering out directories older than 30 days yet, just wanted to see if there was anything I could change with this code.<br>
Am I going about this the wrong way, is there an easier solution to this? Any questions or whatever then let me know, thanks!


