Globbing files by their creation date

Discussion in 'Python' started by tkpmep@hotmail.com, Jan 16, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Guest

    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
    , Jan 16, 2007
    #2
    1. Advertising

  3. James Antill Guest

    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.and.org/and-httpd/ -- $2,000 security guarantee
    http://www.and.org/vstr/
    James Antill, Jan 16, 2007
    #3
  4. Guest

    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, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,193
    Michael Borgwardt
    May 30, 2004
  2. Thomas Philips

    Case-insensitive globbing

    Thomas Philips, Jun 3, 2004, in forum: Python
    Replies:
    4
    Views:
    571
    Derek Chen-Becker
    Jun 3, 2004
  3. Replies:
    5
    Views:
    400
  4. Scott Bass

    globbing files with spaces in the path

    Scott Bass, Jan 6, 2006, in forum: Perl Misc
    Replies:
    10
    Views:
    291
    Henry Law
    Jan 7, 2006
  5. Replies:
    1
    Views:
    79
    martin
    Jun 9, 2006
Loading...

Share This Page