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 533451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:30:36+00:00 2026-05-13T09:30:36+00:00

I am trying to have an automated script that enters into the most recently

  • 0

I am trying to have an automated script that enters into the most recently created folder.

I have some code below

import datetime, os, shutil 

today = datetime.datetime.now().isoformat() 
file_time = datetime.datetime.fromtimestamp(os.path.getmtime('/folders*')) 

if file_time < today: 
    changedirectory('/folders*') 

I am not sure how to get this to check the latest timestamp from now. Any ideas?

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-05-13T09:30:36+00:00Added an answer on May 13, 2026 at 9:30 am

    There is no actual trace of the “time created” in most OS / filesystems: what you get as mtime is the time a file or directory was modified (so for example creating a file in a directory updates the directory’s mtime) — and from ctime, when offered, the time of the latest inode change (so it would be updated by creating or removing a sub-directory).

    Assuming you’re fine with e.g. “last-modified” (and your use of “created” in the question was just an error), you can find (e.g.) all subdirectories of the current directory:

    import os
    
    all_subdirs = [d for d in os.listdir('.') if os.path.isdir(d)]
    

    and get the one with the latest mtime (in Python 2.5 or better):

    latest_subdir = max(all_subdirs, key=os.path.getmtime)
    

    If you need to operate elsewhere than the current directory, it’s not very different, e.g.:

    def all_subdirs_of(b='.'):
      result = []
      for d in os.listdir(b):
        bd = os.path.join(b, d)
        if os.path.isdir(bd): result.append(bd)
      return result
    

    the latest_subdir assignment does not change given, as all_subdirs, any list of paths
    (be they paths of directories or files, that max call gets the latest-modified one).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some CSV data files that I want to import into mySQL. I
Trying to have my PHP script return some SQL table queries. Here's my script
I have some SQL scripts that I'm trying to automate. In the past I
I am trying to implemment automated tests for my app. I have sliding drawer
We are trying to setup an automated deployment environemt with Git/Github. We have 3
We have a process that I'm trying to automate in which I have to
I am trying to run lame from a php script. I have tried these,
Im trying to write a bash script that executes several commands as different users
I currently have a script that takes 1,000 rows at a time from a
i'm trying to create an script that automates the logging in to a website

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.