Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How do I get the creation date of a file?

Reply
Thread Tools

How do I get the creation date of a file?

 
 
marek4130@gmail.com
Guest
Posts: n/a
 
      08-15-2006
Ruby's file class has three methods for querying time related data:
atime, ctime and mtime. None of these will give me the creation date of
a file. Anyone got a clue?

This is what the rubydoc says:
atime Returns the last access time for the named file.
ctime Returns the change time for the named file (the time at which
directory information about the file was changed, not the file itself).
mtime Returns the modification time for the named file.

Thanx,

marek

 
Reply With Quote
 
 
 
 
gwtmp01@mac.com
Guest
Posts: n/a
 
      08-15-2006

On Aug 15, 2006, at 5:05 PM, wrote:

> Ruby's file class has three methods for querying time related data:
> atime, ctime and mtime. None of these will give me the creation
> date of
> a file. Anyone got a clue?


There is no such thing as a creation time of a file. That is to say
such information
isn't stored in the filesystem. If you think about it, it is a
somewhat vague notion.
What should be the creation time of a file that was restored from a
backup tape/disk?
Or a file that is copied from one computer to another? Do you want
the time
the file was created on the original machine, or the time it was
created on the
current machine?

BTW, this isn't a Ruby issue. The atime, ctime, and mtime methods you
mention are just wrappers over the underlying information provided by
Posix-type file systems. Ruby is just a conduit for the information
in this case
and it can't provide information like the 'create time' if it doesn't
already exist
in the underlying filesystem.

Gary Wright

 
Reply With Quote
 
 
 
 
Chad Perrin
Guest
Posts: n/a
 
      08-15-2006
On Wed, Aug 16, 2006 at 06:25:02AM +0900, wrote:
>
> On Aug 15, 2006, at 5:05 PM, wrote:
>
> >Ruby's file class has three methods for querying time related data:
> >atime, ctime and mtime. None of these will give me the creation
> >date of
> >a file. Anyone got a clue?

>
> There is no such thing as a creation time of a file.


That's not precisely true -- the actual creation time of a file is the
last time it was modified, since a "file" is a "virtual" construct for
the benefit of humans. Files are actually represented on the filesystem
as nothing more than an index entry of sorts that tells the read-write
heads where to go looking for data stored on the drive that will be
presented as an atomic object to the user via the virtual filesystem,
and every time the file is changed in some way that index entry
disappears and is replaced by a new entry.

Thus, I suppose the "file" is created anew every time you touch the
thing.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"A script is what you give the actors. A program
is what you give the audience." - Larry Wall

 
Reply With Quote
 
Jeremy Tregunna
Guest
Posts: n/a
 
      08-15-2006

On 06-08-15, at 17:25, wrote:

>
> On Aug 15, 2006, at 5:05 PM, wrote:
>
>> Ruby's file class has three methods for querying time related data:
>> atime, ctime and mtime. None of these will give me the creation
>> date of
>> a file. Anyone got a clue?

>
> There is no such thing as a creation time of a file. That is to
> say such information
> isn't stored in the filesystem.


That is incorrect. It is however, platform specific. On BSD systems,
the creation date of a file is stored, and can be retrieved using for
example, stat(1). Example:

% stat /bin/ls [17:32:52]
device 234881026
inode 1928485
mode 33133
nlink 1
uid 0
gid 0
rdev 0
size 32460
atime 1155674758
mtime 1111445359
ctime 1136127994
blksize 4096
blocks 64
link

Note the ctime. You can fetch this programmatically to.

That said, the creation time is the initial modification time in so
much as that it doesn't record when the file was created, but rather,
when it was created on the filesystem. So your document could be 30
years old, the ctime will report the time you put it on the filesystem.

> Gary Wright


--
Jeremy Tregunna



"One serious obstacle to the adoption of good programming languages
is the notion that everything has to be sacrificed for speed. In
computer languages as in life, speed kills." -- Mike Vanier


 
Reply With Quote
 
nobu@ruby-lang.org
Guest
Posts: n/a
 
      08-16-2006
Hi,

At Wed, 16 Aug 2006 06:53:39 +0900,
Jeremy Tregunna wrote in [ruby-talk:208696]:
> Note the ctime. You can fetch this programmatically to.


Isn't it the change time?

It is platform specific indeed. Windows calls the creation
time as ctime.

--
Nobu Nakada

 
Reply With Quote
 
Rimantas Liubertas
Guest
Posts: n/a
 
      08-16-2006
> At Wed, 16 Aug 2006 06:53:39 +0900,
> Jeremy Tregunna wrote in [ruby-talk:208696]:
> > Note the ctime. You can fetch this programmatically to.

>
> Isn't it the change time?
>
> It is platform specific indeed. Windows calls the creation
> time as ctime.


atime - last access
mtime - modified
ctime - created



Regards,
Rimantas
--
http://rimantas.com/

 
Reply With Quote
 
Justin Collins
Guest
Posts: n/a
 
      08-16-2006
Rimantas Liubertas wrote:
>> At Wed, 16 Aug 2006 06:53:39 +0900,
>> Jeremy Tregunna wrote in [ruby-talk:208696]:
>> > Note the ctime. You can fetch this programmatically to.

>>
>> Isn't it the change time?
>>
>> It is platform specific indeed. Windows calls the creation
>> time as ctime.

>
> atime - last access
> mtime - modified
> ctime - created
>
>
>
> Regards,
> Rimantas
> --
> http://rimantas.com/
>


Ruby docs say:

"Returns the change time for the named file (the time at which directory
information about the file was changed, not the file itself)."

-Justin

 
Reply With Quote
 
Justin Collins
Guest
Posts: n/a
 
      08-16-2006
Justin Collins wrote:
> Rimantas Liubertas wrote:
>>> At Wed, 16 Aug 2006 06:53:39 +0900,
>>> Jeremy Tregunna wrote in [ruby-talk:208696]:
>>> > Note the ctime. You can fetch this programmatically to.
>>>
>>> Isn't it the change time?
>>>
>>> It is platform specific indeed. Windows calls the creation
>>> time as ctime.

>>
>> atime - last access
>> mtime - modified
>> ctime - created
>>
>>
>>
>> Regards,
>> Rimantas
>> --
>> http://rimantas.com/
>>

>
> Ruby docs say:
>
> "Returns the change time for the named file (the time at which
> directory information about the file was changed, not the file itself)."
>
> -Justin
>

Oops, I forgot to mention that's for File.ctime:

File.ctime(file_name) => time

Returns the change time for the named file (the time at which directory
information about the file was changed, not the file itself).



-Justin

 
Reply With Quote
 
gwtmp01@mac.com
Guest
Posts: n/a
 
      08-16-2006

On Aug 16, 2006, at 3:12 PM, rak rok wrote:
> To clarify, as Jeremy indicated, this is actually the inode
> creation time.
> So if you mv a file around within the same mount point, the ctime
> doesn't
> change. If you mv accross mountpoints, a new inode gets created,
> and ctime
> changes.


It isn't the inode creation time. It is the inode *change* time. So
yes, it
is set when an inode is created but it is also changed whenever
information in
the inode changes such as: file ownership, file permissions, file
*length*, and
so on.

Perhaps there is something like 'file creation time' or 'inode
creation time'
in non-Unix, non-Posix file systems. Someone else will have to
answer that
question.

As I said before, the concept of 'file creation time' is pretty fuzzy
and
in any case isn't represented by any of the time stamps found in a a
Posix-like
file system (atime, mtime, ctime).


 
Reply With Quote
 
Chad Perrin
Guest
Posts: n/a
 
      08-16-2006
On Thu, Aug 17, 2006 at 04:06:39AM +0900, Justin Collins wrote:
> Justin Collins wrote:
> >
> >Ruby docs say:
> >
> >"Returns the change time for the named file (the time at which
> >directory information about the file was changed, not the file itself)."
> >
> >-Justin
> >

> Oops, I forgot to mention that's for File.ctime:
>
> File.ctime(file_name) => time
>
> Returns the change time for the named file (the time at which directory
> information about the file was changed, not the file itself).


That is, effectively, creation time (for a particular definition of file
creation). It returns the time at which the file's listing in the
information for the enclosing directory changed, which basically means
when it was created within that directory. Same difference. I do think
the letter C stands for "change" in this case, though, not only in Ruby
docs, but in POSIX standards as well.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts." - Paul Graham

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to (batch) set EXIF date taken and IPTC creation date and creation time for photos with filenames YYMMDDHHMMSS#.jpg? guercheLE@gmail.com Digital Photography 1 10-04-2005 07:15 PM
copy EXIF date to IPTC creation date Israel Hsu Digital Photography 0 08-04-2005 08:04 AM
javascript to get the creation date and time of the file sent and display it in the html page ? Fabrizio Javascript 2 10-05-2004 08:52 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57