Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:09:36+00:00 2026-06-08T21:09:36+00:00

I’ve gave it a decent attempt based on other answers I’ve found but haven’t

  • 0

I’ve gave it a decent attempt based on other answers I’ve found but haven’t managed anything solid (my solution is horrifically slow but maybe there’s no other way). Basically, I have a folder called “scratch” where users can create there own folders to dump their data.
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:

    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.
Am I going about this the wrong way, is there an easier solution to this? Any questions or whatever then let me know, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:09:37+00:00Added an answer on June 8, 2026 at 9:09 pm

    I would use:

    import os
    from os.path import join
    from datetime import datetime, timedelta
    from operator import itemgetter
    
    
    def list_user_files(username):
        for root, dirs, files in os.walk(username):
            for name in files:
                fullname = join(root, name)
                try:
                    yield fullname, os.stat(fullname).st_mtime
                except (IOError, OSError) as e: # will catch WindowsError but more generic
                    pass # Do something here...
    
    
    ROOT = '/home'
    CUTOFF = timedelta(days=30)
    for userdir in os.listdir(ROOT):
        most_recent = max(list_user_files(join(ROOT, userdir)), key=itemgetter(1))
        print '{}: most recent file and timestamp is {}'.format(userdir, most_recent)
        if (datetime.now() - datetime.fromtimestamp(most_recent[1])) > CUTOFF:
            print '{} has not used their folder during cutoff period'.format(userdir)
    

    Debugging max ValueError (put this in place of most_recent= line):

    try:
        most_recent = max(list_user_files(join(ROOT, userdir)), key=itemgetter(1))
    except ValueError as e:
        print '***DEBUG***', list(list_user_files(join(ROOT, userdir)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.