What's up with File.ctime?

P

Peter Bailey

Hello,
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?

Thanks,
Peter
 
J

Jan Svitok

Hello,
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?

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
 
P

Peter Bailey

Jan said:
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

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

Jan Svitok

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.

Well, I thought ctime = creation time ;-) Now I've learned something as well.
 
G

gwtmp01

Well, I thought ctime = creation time ;-) Now I've learned
something as well.

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
 
H

Hugh Sasse

Hello,
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. [...]
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?

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

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
 
P

Peter Bailey

Hugh said:
Hello,
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. [...]
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?

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

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

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

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

No members online now.

Forum statistics

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

Latest Threads

Top