在磁盘上有一文本,我想用DELPHI编写一段程序来获得该文本文件的创建时间,不知该怎么做?求救高手指点!

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      hFile: LongWord;
      fc, fa, fw: _FileTime;
      d1, d2, d3: _SystemTime;
      aa: _OFSTRUCT;
    begin
      if not OpenDialog1.Execute then Exit;
      hFile := OpenFile(PChar(OpenDialog1.FileName), aa, OF_READWRITE);
      if GetFileTime(hFile, @fc, @fa, @fw) then
      begin
        FileTimeToSystemTime(fc, D1);
        FileTimeToSystemTime(fa, D2);
        FileTimeToSystemTime(fw, D3);
        ShowMessage('创建时间:' + FormatDateTime('YYYY-MM-DD HH:NN:SS', SystemTimeToDateTime(d1)) + #13#10 +
                    '上次访问时间:' + FormatDateTime('YYYY-MM-DD HH:NN:SS', SystemTimeToDateTime(d2)) + #13#10 +
                    '上次修改时间:' + FormatDateTime('YYYY-MM-DD HH:NN:SS', SystemTimeToDateTime(d3)));
      end;
    end;
      

  2.   

    uses IdGlobal; {其为IdGlobal中单元,原函数取最后访问时间,你可自己改之,下面是改过的}function GetFileCreationTime(const Filename: string): TDateTime;
    var
      Data: TWin32FindData;
      H: THandle;
      FT: TFileTime;
      I: Integer;
    begin
      H := FindFirstFile(PCHAR(Filename), Data);
      if H <> INVALID_HANDLE_VALUE then begin
        try
          FileTimeToLocalFileTime(Data.ftCreationTime, FT);  //其中参数
          FileTimeToDosDateTime(FT, LongRec(I).Hi, LongRec(I).Lo);
          Result := FileDateToDateTime(I);
        finally
          Windows.FindClose(H);
        end
      end else begin
        Result := 0;
      end;
    end;------
    Data.ftLastWriteTime  最后修改时间
         ftCreationTime: TFileTime;  创建时间
         ftLastAccessTime: TFileTime; 最后访问时间
         ftLastWriteTime: TFileTime;