Accessing the files by last modified time

Chris Rebert clp2 at rebertia.com
Thu Mar 22 12:49:23 CET 2012


On Thu, Mar 22, 2012 at 4:33 AM, Sangeet <mrsangeet at gmail.com> wrote:
> Hi
>
> I am new to the python programming language.
>
> I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP.
>
> I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either.

Recursively or non-recursively?
Live monitoring or just one-time?
What was the forum post in question?

In the simple case, you just need to stitch together these functions:
http://docs.python.org/library/os.html#os.stat
(note the .st_mtime attribute of the result)
http://docs.python.org/library/os.path.html#os.path.join
with one of these functions:
http://docs.python.org/library/os.html#os.listdir
http://docs.python.org/library/os.html#os.walk

Cheers,
Chris



More information about the Python-list mailing list