Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   How do I get the creation date of a file? (http://www.velocityreviews.com/forums/t832480-how-do-i-get-the-creation-date-of-a-file.html)

marek4130@gmail.com 08-15-2006 09:00 PM

How do I get the creation date of a file?
 
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


gwtmp01@mac.com 08-15-2006 09:25 PM

Re: How do I get the creation date of a file?
 

On Aug 15, 2006, at 5:05 PM, marek4130@gmail.com 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


Chad Perrin 08-15-2006 09:40 PM

Re: How do I get the creation date of a file?
 
On Wed, Aug 16, 2006 at 06:25:02AM +0900, gwtmp01@mac.com wrote:
>
> On Aug 15, 2006, at 5:05 PM, marek4130@gmail.com 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


Jeremy Tregunna 08-15-2006 09:53 PM

Re: How do I get the creation date of a file?
 

On 06-08-15, at 17:25, gwtmp01@mac.com wrote:

>
> On Aug 15, 2006, at 5:05 PM, marek4130@gmail.com 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
jtregunna@blurgle.ca


"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



nobu@ruby-lang.org 08-16-2006 05:16 AM

Re: How do I get the creation date of a file?
 
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


Rimantas Liubertas 08-16-2006 09:22 AM

Re: How do I get the creation date of a file?
 
> 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/


Justin Collins 08-16-2006 07:04 PM

Re: How do I get the creation date of a file?
 
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


Justin Collins 08-16-2006 07:06 PM

Re: How do I get the creation date of a file?
 
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


gwtmp01@mac.com 08-16-2006 07:26 PM

Re: How do I get the creation date of a file?
 

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



Chad Perrin 08-16-2006 09:39 PM

Re: How do I get the creation date of a file?
 
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



All times are GMT. The time now is 10:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.