By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

Globbing files by their creation date

P: n/a
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

Jan 16 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

ThomasI've used glob.glob to create a list of all files whose name
Thomasmatches a substring, but I don't see how I can use it to
Thomasidentify 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
Jan 16 '07 #2

P: n/a
On Tue, 16 Jan 2007 07:44:29 -0600, skip wrote:
ThomasI've used glob.glob to create a list of all files whose name
Thomasmatches a substring, but I don't see how I can use it to
Thomasidentify 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 -- ja***@and.org
http://www.and.org/and-httpd/ -- $2,000 security guarantee
http://www.and.org/vstr/
Jan 16 '07 #3

P: n/a

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

Jan 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.