Mar 22, 2012 11:33 am
SangeetHi
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.
Thanks,
Sangeet
Mar 22, 2012 11:49 am
Chris RebertOn Thu, Mar 22, 2012 at 4:33 AM, Sangeet <mrsangeet@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.
>
> 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
Mar 22, 2012 12:04 pm
Tim WilliamsOn Mar 22, 7:33 am, Sangeet <mrsang...@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.
>
> Thanks,
> Sangeet
>
> 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.
>
> Thanks,
> Sangeet
Check out os.stat()
Mar 22, 2012 12:38 pm
Peter OttenSangeet wrote:
> 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.
> file in one of my directories. I'm using Win XP.
import os
import glob
path = r"c:\one\of\my directories\*"
youngest_file = max(glob.glob(path), key=os.path.getmtime)
Previous Thread: Best way to disconnect from ldap?
Next Thread: Number of languages known [was Re: Python is readable] - somewhat OT
Related Forum Topics
- Help accessing COM .dll from Python
- Modifying a time.struct_time
- PyHook and time libraries
- Problem with eval and time
- Average time calculation??
- Real time event accuracy
- Limited time offer, so hurry up!
- Why does dead code costs time?
- An object is and isn't an instance of a class at the same time
- PyWarts: time, datetime, and calendar modules