[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How do I get the creation date of a file?

marek4130

8/15/2006 9:00:00 PM

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

13 Answers

Gary Wright

8/15/2006 9:25:00 PM

0


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

8/15/2006 9:40:00 PM

0

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.ap... ]
"A script is what you give the actors. A program
is what you give the audience." - Larry Wall

Jeremy Tregunna

8/15/2006 9:54:00 PM

0


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


Jeff Schwab

8/16/2006 2:32:00 AM

0

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.

Some popular filesystems do store creation times.

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

The creation time of the original file. Otherwise, it's not a
restoration, but a copy.

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

NTFS, at least, preserves the creation time from the original file.

Jeff Schwab

8/16/2006 2:33:00 AM

0

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

As others have pointed out, you might not be able to get this
information in a portable way. Are you targetting a particular
platform? Are you running on Windows/Linux/Other?

Nobuyoshi Nakada

8/16/2006 5:16:00 AM

0

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

8/16/2006 9:23:00 AM

0

> 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://rim...

Justin Collins

8/16/2006 7:05:00 PM

0

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://rim...
>

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

8/16/2006 7:07:00 PM

0

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://rim...
>>
>
> 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

Gary Wright

8/16/2006 7:27:00 PM

0


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