Article View: borland.public.cppbuilder.nativeapi
Article #15622Re: File Last Write Time
From: Giuliano
Date: Mon, 23 Jun 2003 16:12
Date: Mon, 23 Jun 2003 16:12
42 lines
2145 bytes
2145 bytes
On Mon, 23 Jun 2003 17:11:50 +0200, "Enrico B." <eangelo@libero.it> wrote:
>Hi to All!
>Can somebody provide me with a piece of code to be used to retrieve a file
>last modification time? I tried "stat" but on Windows O.S. that function
>only returns the last access time. I also tried GetFileTime but something is
>wrong with it.
>Thanks in advance
>Henry
>
>
TDateTime __fastcall GetLastWriteTime( AnsiString File )
{
WIN32_FIND_DATA FindFileData;
HANDLE HFile = FindFirstFile( File.c_str(), &FindFileData );
if ( HFile == INVALID_HANDLE_VALUE )
RaiseLastOSError();
class X {
public:
X( HANDLE hFile ) : hFile_( hFile ) {}
~X() throw() { FindClose( hFile_ ); }
private:
const HANDLE hFile_;
}
Finalize( HFile );
FILETIME LT;
if ( !FileTimeToLocalFileTime( &FindFileData.ftLastWriteTime, < ) )
RaiseLastOSError();
SYSTEMTIME ST;
if ( !FileTimeToSystemTime( <, &ST ) )
RaiseLastOSError();
return TDateTime( ST.wYear, ST.wMonth, ST.wDay ) +
TDateTime( ST.wHour, ST.wMinute, ST.wSecond, ST.wMilliseconds );
}
Technical Details
Message-ID:
<sg9efvog0r2vcvi87adq64d9ov0tbu8mjp@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3ef71448@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,df83c650f00e2702 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-23 09:23:01 PST From: Giuliano <gcardinali@remove.adhoc.net> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: File Last Write Time Date: Mon, 23 Jun 2003 18:12:13 +0200 Message-ID: <sg9efvog0r2vcvi87adq64d9ov0tbu8mjp@4ax.com> References: <3ef71448@newsgroups.borland.com> X-Newsreader: Forte Agent 1.91/32.564 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 213.152.192.189 X-Trace: newsgroups.borland.com 1056384976 213.152.192.189 (23 Jun 2003 09:16:16 -0700) Lines: 43 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail