在Delphi中判断一个文件的日期是否是当天的日期,
如果是当天的时间然后拷贝到别的盘上

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if Trunc(FileDateToDateTime(FileAge('C:\temp\temp.txt'))) = Trunc(Date) then
        CopyFile('C:\temp\temp.txt', 'C:\temp\temp.bak', True);
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      h: Integer;
      D: TDateTime;
      DD: TDate;
    begin
      h := FileCreate('F:\资料\StringToWideStringEx.txt');
      D := FileDateToDateTime(FileGetDate(h));
      DD := TDate(D);
      if DD = TDate(Now) then
        ShowMessage(DateToStr(DD));
      FileClose(h);
    end;
      

  3.   

    TimeType,参数为 0,1,2/分别为:// 分别为获取文件创建,更改,最后修改时间function TForm1.FGetFileTime(sFileName: string;
              TimeType: Integer): TDateTime;
    var
       ffd:TWin32FindData;
       dft:DWord;
       lft,Time:TFileTime;
       H:THandle;
    begin
         H:=Windows.FindFirstFile(PChar(sFileName),ffd);
         case  TimeType of
               0: Time:=ffd.ftCreationTime;
               1: Time:=ffd.ftLastWriteTime;
               2: Time:=ffd.ftLastAccessTime;
         end;     //获取文件信息
         if (H <> INVALID_HANDLE_VALUE) then
         begin
              //我们只查找一个文件,所以关掉"find"
              Windows.FindClose(H);
              //转换FILETIME格式成为local  FILETIME格式
              FileTimeToLocalFileTime(Time,lft);
              //转换FILETIME格式成为DOStime格式
              FileTimeToDosDateTime(lft,LongRec(dft).Hi,LongRec(dft).Lo);
              //最后,转换DOStime格式成为Delphi's应用的TdateTime格式
              Result:=FileDateToDateTime(dft);
         end
         else
             result:=0;
    end;