Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Globbing files by their creation date

Reply
Thread Tools

Globbing files by their creation date

 
 
tkpmep@hotmail.com
Guest
Posts: n/a
 
      01-16-2007
I'd like to create a list of all files in a directory that were created
after a certain date. How does one do this? I've used glob.glob to
create a list of all files whose name matches a substring, but I don't
see how I can use it to identify files by their creation date.

Thanks in advance for the assistance.

Thomas Philips

 
Reply With Quote
 
 
 
 
skip@pobox.com
Guest
Posts: n/a
 
      01-16-2007

Thomas> I've used glob.glob to create a list of all files whose name
Thomas> matches a substring, but I don't see how I can use it to
Thomas> identify files by their creation date.

Sumthin' like:

files = [f for f in glob.glob(globpat)
if os.path.getctime(f) > timethreshold]

Define globpat and timethreshold accordingly. You sure you don't mean
modification time? If so, change getctime to getmtime.

Skip
 
Reply With Quote
 
 
 
 
James Antill
Guest
Posts: n/a
 
      01-16-2007
On Tue, 16 Jan 2007 07:44:29 -0600, skip wrote:

> Thomas> I've used glob.glob to create a list of all files whose name
> Thomas> matches a substring, but I don't see how I can use it to
> Thomas> identify files by their creation date.
>
> Sumthin' like:
>
> files = [f for f in glob.glob(globpat)
> if os.path.getctime(f) > timethreshold]
>
> Define globpat and timethreshold accordingly. You sure you don't mean
> modification time? If so, change getctime to getmtime.


help(os.path.getctime)

getctime(filename)
Return the metadata change time of a file, reported by os.stat().

Note that _change_ time != creation time. Also for all files you probably
want os.listdir() instead of glob.

--
James Antill -- http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.and.org/and-httpd/ -- $2,000 security guarantee
http://www.and.org/vstr/
 
Reply With Quote
 
tkpmep@hotmail.com
Guest
Posts: n/a
 
      01-17-2007

Thanks a mill - os.path.getctime(f) is what I needed. Unfortunately, my
attempts to turn the integer it returns into a date have failed.

>>> os.path.getctime(fn) #fn was created today, 1/17/2007

1168955503

I tried to convert this to a date object by typing
>>>datetime.date.fromordinal(1168955503)


Traceback (most recent call last):
File "<pyshell#9>", line 1, in -toplevel-
datetime.date.fromordinal(1168955503)
ValueError: year is out of range

How can I do the conversion? I'm trying to identify all files that were
created after YYYY/MM/DD.

For a quick sanity check, I ran
>>> datetime.date.today().toordinal()

732693

which is orders of magnitude smaller than the number returned by
os.path.getctime(fn).

Thanks in advance for your help

Thomas Philips

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with Globbing : use of -r with glob catches only half of the matching files ... xhoster@gmail.com Perl Misc 1 06-09-2006 09:10 PM
globbing files with spaces in the path Scott Bass Perl Misc 10 01-07-2006 01:39 PM
How to (batch) set EXIF date taken and IPTC creation date and creation time for photos with filenames YYMMDDHHMMSS#.jpg? guercheLE@gmail.com Digital Photography 1 10-04-2005 07:15 PM
copy EXIF date to IPTC creation date Israel Hsu Digital Photography 0 08-04-2005 08:04 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments