Globbing files by their creation date

T

tkpmep

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
 
S

skip

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
 
J

James Antill

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.
 
T

tkpmep

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.
1168955503

I tried to convert this to a date object by typing
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 ran732693

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

Thanks in advance for your help

Thomas Philips
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top