Board index » delphi » Grabbing the date and time stamp of a file

Grabbing the date and time stamp of a file

Quote
In article <4e3a9o$...@newsbf02.news.aol.com> ttss...@aol.com (TTSSInc) writes:
>From: ttss...@aol.com (TTSSInc)
>Subject: Grabbing the date and time stamp of a file
>Date: 23 Jan 1996 13:44:08 -0500
>I am using BP 7.0 for DOS, and am looking for a way to grab
>the date and time stamp of a file on the hard disk.  I want to
>be able to display that information in a writeln statement, such
>as:
>"The data file is current as of 1/23/96 5:35:24 PM."
>Any ideas?

Sure, grabbing the stamp is easy, formatting takes a little work.

program getstamp;

uses
  dos;

var
  name : string;
  s : searchrec;

function formatstamp (time : longint) : string;

var
  dt : datetime;

begin
  unpacktime (time,dt);
  {write your formatter here using the fields of the dt record.}
end;

begin
  write ('File to find time/date: ');
  readln (name);
  findfirst (name,anyfile,s);
  if doserror=0 then
    writeln ('The time of this file is:  ',formatstamp(s.time),'.')
  else
    writeln ('File not found.');
end.

I have code for a time stamp formatter I've submitted to SWAG.  If you have
SWAG, you can get it there or if you want a copy of it, e-mail me.  It's
fairly configurable.

Quote
>--
>Steve Murray
>Programmer, TTSS Inc.

--
Scott F. Earnest             |0100100001000001010010010100110000100000|
sc...@whiplash.res.cmu.edu   |0100010101010010010010010101001100100001|
Head Pope, Non-Extant Temple of Afrodite, Goddess of Funky 70's Hairdos -><-
      YOU'VE BEEN LIED TO:  Possession is only one tenth of the law.
                The other nine tenths is really STUPIDITY!
 

Re:Grabbing the date and time stamp of a file


I am using BP 7.0 for DOS, and am looking for a way to grab
the date and time stamp of a file on the hard disk.  I want to
be able to display that information in a writeln statement, such
as:

"The data file is current as of 1/23/96 5:35:24 PM."

Any ideas?

--
Steve Murray
Programmer, TTSS Inc.

Re:Grabbing the date and time stamp of a file


Quote
TTSSInc wrote:

> I am using BP 7.0 for DOS, and am looking for a way to grab
> the date and time stamp of a file on the hard disk.  I want to
> be able to display that information in a writeln statement, such
> as:

> "The data file is current as of 1/23/96 5:35:24 PM."

        The basic idea is that u use the Findfirst procedure to find the
file with a Search Record. The search record (SearchRec type in the DOS
unit) has time, date, name, size and some other info in it to. Consult
your help file for more info..

----------------------------------------------------------------------
    Paul Matthews - Lead Programmer : Creative Logic Software
     Check out Reality's Fringes at http://www.singnet.com.sg/~pmatth/
----------------------------------------------------------------------

Re:Grabbing the date and time stamp of a file


Quote
Paul Matthews <Pma...@singnet.com.sg> wrote:
>    The basic idea is that u use the Findfirst procedure to find the
>file with a Search Record. The search record (SearchRec type in the DOS
>unit) has time, date, name, size and some other info in it to. Consult
>your help file for more info..

Or look at my tutorial at the URL listed below (in part 8
specifically).

Glenn Grotzinger
mailto:ggr...@2sprint.net
MOD and S3M user extraordinaire.
Writer of TP tutorial.  All released parts findable at:
ftp://garbo.uwasa.fi/pc/turbopas/tptutr0a.zip

Re:Grabbing the date and time stamp of a file


Quote
Paul Matthews <Pma...@singnet.com.sg> writes:
>> "The data file is current as of 1/23/96 5:35:24 PM."

> The basic idea is that u use the Findfirst procedure to find the
> file with a Search Record.

or just do it directly:

function getfntime(fn: string): longint;

var
  result: longint;
  f: text;

begin
  result := 0;

  assign(f,fn);
{$I-}
  reset(f);
{$I+}
  if ioresult=0 then
    begin
      getftime(f,result);
      close(f);
    end;

  getfntime := result;
end;

function getfnsize(fn: string): longint;

var
  result: longint;
  f: file;

begin
  result := -1;

  assign(f,fn);
{$I-}
  reset(f,1);
{$I+}
  if ioresult=0 then
    begin
      result := filesize(f);
      close(f);
    end;

  getfnsize := result;
end;
--
Russell_Sch...@locutus.ofB.ORG  Shad 86c

Other Threads