Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22015 > unrolled thread
| Started by | Sangeet <mrsangeet@gmail.com> |
|---|---|
| First post | 2012-03-22 04:33 -0700 |
| Last post | 2012-03-22 13:38 +0100 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.python
Accessing the files by last modified time Sangeet <mrsangeet@gmail.com> - 2012-03-22 04:33 -0700
Re: Accessing the files by last modified time Chris Rebert <clp2@rebertia.com> - 2012-03-22 04:49 -0700
Re: Accessing the files by last modified time Sangeet <mrsangeet@gmail.com> - 2012-03-23 06:00 -0700
Re: Accessing the files by last modified time Sangeet <mrsangeet@gmail.com> - 2012-03-23 06:00 -0700
Re: Accessing the files by last modified time Tim Williams <tjandacw@cox.net> - 2012-03-22 05:04 -0700
Re: Accessing the files by last modified time Neil Cerutti <neilc@norwich.edu> - 2012-03-22 13:06 +0000
Re: Accessing the files by last modified time Sangeet <mrsangeet@gmail.com> - 2012-03-23 05:59 -0700
Re: Accessing the files by last modified time Peter Otten <__peter__@web.de> - 2012-03-22 13:38 +0100
| From | Sangeet <mrsangeet@gmail.com> |
|---|---|
| Date | 2012-03-22 04:33 -0700 |
| Subject | Accessing the files by last modified time |
| Message-ID | <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> |
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
[toc] | [next] | [standalone]
| From | Chris Rebert <clp2@rebertia.com> |
|---|---|
| Date | 2012-03-22 04:49 -0700 |
| Message-ID | <mailman.882.1332416966.3037.python-list@python.org> |
| In reply to | #22015 |
On 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. 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
[toc] | [prev] | [next] | [standalone]
| From | Sangeet <mrsangeet@gmail.com> |
|---|---|
| Date | 2012-03-23 06:00 -0700 |
| Message-ID | <mailman.920.1332507627.3037.python-list@python.org> |
| In reply to | #22016 |
On Thursday, 22 March 2012 17:19:23 UTC+5:30, Chris Rebert wrote: > On 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. > > 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 Thanks Chris, this helped me a lot!
[toc] | [prev] | [next] | [standalone]
| From | Sangeet <mrsangeet@gmail.com> |
|---|---|
| Date | 2012-03-23 06:00 -0700 |
| Message-ID | <28803503.136.1332507625424.JavaMail.geo-discussion-forums@ynjk1> |
| In reply to | #22016 |
On Thursday, 22 March 2012 17:19:23 UTC+5:30, Chris Rebert wrote: > On 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. > > 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 Thanks Chris, this helped me a lot!
[toc] | [prev] | [next] | [standalone]
| From | Tim Williams <tjandacw@cox.net> |
|---|---|
| Date | 2012-03-22 05:04 -0700 |
| Message-ID | <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> |
| In reply to | #22015 |
On 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 Check out os.stat()
[toc] | [prev] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2012-03-22 13:06 +0000 |
| Message-ID | <9t0mesFnj3U1@mid.individual.net> |
| In reply to | #22017 |
On 2012-03-22, Tim Williams <tjandacw@cox.net> wrote: > On 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 > > Check out os.stat() I've been using os.path.getmtime, and converting that to a datetime object using datetime.datetime.fromtimestamp. Surprisingly, perhaps, this has been working. According to the docs, to avoid making any assumptiong, I might need to do: tm = os.path.getmtime(apath) lt = time.localtime(tm) datetime.datetime(lt.tm_year, lt.tm_mon, lt.tm_mday) Here's where I'm confused about the functioning of my original plan. The docs say: os.path.getmtime [...] The return value is a number giving the number of seconds since the epoch (see the time module). [...] classmethod datetime.fromtimestamp Return the local date and time corresponding to the POSIX timestamp, such as returned by time.time(). [...] time.time Return the time as a floating point number expressed as seconds since the epoch, in UTC. [...] I'm not completely sure the return type of getmtime and the argument type of fromtimestamp are really the same or not. I guess I came to that conclusion some time in the past, and it does seem to work. It may be a simple case of just different aspects the exact same type being being highlighted in each definition. -- Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | Sangeet <mrsangeet@gmail.com> |
|---|---|
| Date | 2012-03-23 05:59 -0700 |
| Message-ID | <23086952.178.1332507576146.JavaMail.geo-discussion-forums@ynes7> |
| In reply to | #22017 |
On Thursday, 22 March 2012 17:34:43 UTC+5:30, Tim Williams wrote: > On 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 > > Check out os.stat() Hey, thanks I tried playing around with this. I haven't got what I exactly wanted, but on the way there for sure! :) Sangeet
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2012-03-22 13:38 +0100 |
| Message-ID | <mailman.883.1332419875.3037.python-list@python.org> |
| In reply to | #22015 |
Sangeet 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. import os import glob path = r"c:\one\of\my directories\*" youngest_file = max(glob.glob(path), key=os.path.getmtime)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web