What's up with File.ctime?

Discussion in 'Ruby' started by Peter Bailey, Nov 14, 2006.

  1. Peter Bailey

    Peter Bailey Guest

    I need to notate the date/time attributes of files. I'm using File.ctime
    and trimming it back to show just day, date, and time.

    filetime = File.ctime(txtfile)
    filetime = filetime.to_s.gsub!(/ -.*$/, "")

    But, I've noticed that files that list in the directories as being dated
    November 8 are showing via ctime as November 13 files. What's up?

    Peter Bailey, Nov 14, 2006
    1. Advertisements

  2. Peter Bailey

    Jan Svitok Guest

    Perhaps dir/ls shows mtime? Try checking mtime/ctime/atime to see
    which is the right one.
    To display ctime on windows, try dir /T:C on unix ls -l --time=ctime
    Jan Svitok, Nov 14, 2006
    1. Advertisements

  3. Peter Bailey

    Peter Bailey Guest

    Thanks, Jan. Actually, I figured it out for myself. Looking deeper into
    it, I found File.stat.mtime, and that's I'm using now, and it works.
    ctime, I guess, stands for "change time," so, it doesn't actually state
    the timestamp of the file as it is. Thanks again.
    Peter Bailey, Nov 14, 2006
  4. Peter Bailey

    Jan Svitok Guest

    Well, I thought ctime = creation time ;-) Now I've learned something as well.
    Jan Svitok, Nov 14, 2006
  5. Peter Bailey

    gwtmp01 Guest

    Just to make things a little clearer:

    the 'change' referenced by 'ctime' is a change to the inode (or
    metadata) for the file. So for example if the ownership or
    permissions of a file change then ctime will be updated. If the
    length of a file is changed (i.e. data is appended to the file) then
    ctime will change. The mtime field on the other hand only changes
    when data is written to the file (either new data appended to the end
    or existing data is modified).

    Lots of people think ctime = 'creation time' but the Posix API
    doesn't actually provide access to a 'create time'.

    I believe some Windows and Mac OS filesystems do have a notion of
    'create time' that is recorded separately from the Posix 'ctime'. I
    don't know what the APIs are
    to access that timestamp on those platforms.

    Gary Wright
    gwtmp01, Nov 14, 2006
  6. Peter Bailey

    Hugh Sasse Guest

    ls -lu ;# => atime
    ls -lc ;# => ctime
    ls -l ;# => mtime

    ctime means Inode modified, i.e. created, chmod'ed, etc. See man ls
    if you're on unix. DIR /T:A gives access time according to XP docs.

    Hugh Sasse, Nov 14, 2006
  7. Peter Bailey

    Peter Bailey Guest

    Thanks, you guys. Nope, I'm on Windows. Yes, "dir /t:a" is probably the
    equivalent to ctime, but, again, that's not what I want. I just want the
    file time as it's listed in a garden-variety "dir."
    Peter Bailey, Nov 14, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.