Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

file date question

56 views
Skip to first unread message

Charles Heizer

unread,
Oct 27, 2005, 7:49:21 PM10/27/05
to
Hello,
Is there a easy way to determin if a file was created or modified with
in the last 24hrs?

Thanks,
- Charles

Himesh P.

unread,
Oct 27, 2005, 8:29:41 PM10/27/05
to

dinaka...@yahoo.com

unread,
Oct 27, 2005, 8:34:01 PM10/27/05
to

Himesh P. wrote:
> file mtime name ?time?
>
> http://www.tcl.tk/man/tcl8.5/TclCmd/file.htm
set mtime [file mtime "filename"]
set last24hr [expr 24 * 60 * 60]
if {$mtime > $last24hr} {
puts "file modified before last 24 hrs"
}
HTH
./dinakar

Fredderic

unread,
Oct 28, 2005, 3:10:43 AM10/28/05
to
On 27 Oct 2005 17:34:01 -0700,
"dinaka...@yahoo.com" <dinaka...@yahoo.com> wrote:

> set mtime [file mtime "filename"]
> set last24hr [expr 24 * 60 * 60]

Shouldn't that be:
set last24hr [expr [clock seconds] - {24 * 60 * 60}]

> if {$mtime > $last24hr} {
> puts "file modified before last 24 hrs"
> }


Fredderic

suchenwi

unread,
Oct 28, 2005, 5:36:11 AM10/28/05
to
Get fancier with [clock scan]:

% clock format [clock scan now]
Fri Oct 28 11:33:57 W. Europe Standard Time 2005
% clock format [clock scan yesterday]
Thu Oct 27 11:34:00 W. Europe Standard Time 2005
% clock format [clock scan "24 hours ago"]
Thu Oct 27 11:35:11 W. Europe Standard Time 2005


So you can write:
set last24hr [clock scan yesterday],
or, for possible finer granularity:
set last24hr [clock scan "24 hours ago"]

Charles Heizer

unread,
Oct 28, 2005, 11:42:17 AM10/28/05
to
Thanks to everyone for helping me out on this one. I was'nt real sure
how to do it. I would think this would be a great example for
Welch,Jones and Hobbs to add to the TCL book.

Thanks agaain,
- Charles

David Zolli

unread,
Oct 28, 2005, 12:09:02 PM10/28/05
to
proc FileChanged {file {hours 24}} {
file stat $file var
set now [clock second]
set AgeM [expr {int(ceil(($now-$var(mtime))/3600.0))}]
set AgeC [expr {int(ceil(($now-$var(mtime))/3600.0))}]
if {$AgeM < $hours || $AgeC < $hours} {
return 1
} else {
return 0
}
}

--
David Zolli - Kroc
http://www.kroc.tk

suchenwi

unread,
Oct 28, 2005, 4:17:00 PM10/28/05
to
AgeM and AgeC are identical... did you mean
set AgeC [expr {int(ceil(($now-$var(ctime))/3600.0))}]
?
And are there cases where ctime isn't mtime? The latter can be had with
just [file mtime $filename].

Glenn Jackman

unread,
Oct 28, 2005, 5:19:21 PM10/28/05
to
At 2005-10-28 04:17PM, suchenwi <richard.suchenw...@siemens.com> wrote:
> And are there cases where ctime isn't mtime? The latter can be had with
> just [file mtime $filename].

I believe ctime indicates changes to the file's inode. For example,
adding a hard link to a file will change the ctime:

% file stat test.tcl a
% clock format $a(ctime)
Fri Nov 07 14:35:52 EST 2003
% clock format $a(mtime)
Fri Nov 07 14:35:52 EST 2003
% exec sh -c "ln test.tcl foobar"
% file stat test.tcl a
% clock format $a(mtime)
Fri Nov 07 14:35:52 EST 2003
% clock format $a(ctime)
Fri Oct 28 17:16:36 EDT 2005


--
Glenn Jackman
NCF Sysadmin
gle...@ncf.ca

Kaitzschu

unread,
Oct 28, 2005, 7:17:17 PM10/28/05
to
On Sat, 28 Oct 2005, Glenn Jackman wrote:

> At 2005-10-28 04:17PM, suchenwi <richard.suchenw...@siemens.com> wrote:
>> And are there cases where ctime isn't mtime? The latter can be had with
>> just [file mtime $filename].
>
> I believe ctime indicates changes to the file's inode. For example,
> adding a hard link to a file will change the ctime:

Yes, ctime tells you the time of physical intervention. When you mess with
the file, ctime gets set. When you mess with contents, mtime is set (and
usually this sets ctime, too, as in-place operations are rare), and when
you just read (and hopefully don't mess it up) atime is set.

So, creation time, modification time and access time.

If that was wrong, I'm more than willing to be corrected, ctime is a bit
of mystery.

--
-Kaitzschu
s="TCL ";while true;do echo -en "\r$s";s=${s:1:${#s}}${s:0:1};sleep .1;done

dinaka...@yahoo.com

unread,
Oct 28, 2005, 10:03:22 PM10/28/05
to

Kaitzschu wrote:
> On Sat, 28 Oct 2005, Glenn Jackman wrote:
>
> > At 2005-10-28 04:17PM, suchenwi <richard.suchenw...@siemens.com> wrote:
> >> And are there cases where ctime isn't mtime? The latter can be had with
> >> just [file mtime $filename].
> >
> > I believe ctime indicates changes to the file's inode. For example,
> > adding a hard link to a file will change the ctime:
>
> Yes, ctime tells you the time of physical intervention. When you mess with
> the file, ctime gets set. When you mess with contents, mtime is set (and
> usually this sets ctime, too, as in-place operations are rare), and when
> you just read (and hopefully don't mess it up) atime is set.
>
> So, creation time, modification time and access time.
>
> If that was wrong, I'm more than willing to be corrected, ctime is a bit
> of mystery

I dont think they are very reliable. One can change the attribes of
time without touching file (opening or accessing file etc). But for
most part they are fine indicators.
./dinakar

Glenn Jackman

unread,
Oct 29, 2005, 1:02:12 PM10/29/05
to
At 2005-10-28 07:17PM, Kaitzschu <kait...@kaitzschu.cjb.net.nospam.plz.invalid> wrote:
> So, creation time, modification time and access time.

"change time" is more apt than "creation time"

David Zolli

unread,
Nov 2, 2005, 2:44:06 AM11/2/05
to
suchenwi a écrit :

> AgeM and AgeC are identical... did you mean
> set AgeC [expr {int(ceil(($now-$var(ctime))/3600.0))}]
> ?

Yes.

Fredderic

unread,
Nov 3, 2005, 5:09:56 AM11/3/05
to
On 28 Oct 2005 02:36:11 -0700,
"suchenwi" <richard.suchenw...@siemens.com> wrote:

> Get fancier with [clock scan]:

> set last24hr [clock scan yesterday],
> or, for possible finer granularity:
> set last24hr [clock scan "24 hours ago"]

Oh, trippy... And about twice as fast, too. :)


Fredderic

0 new messages