望高手们能帮我解决!!

sdlxj 2002-03-02 01:03:11
delphi怎样才能读取一个文件夹里每个文件的修改日期和系统当天的日期?
...全文
34 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdlxj 2002-03-03
  • 打赏
  • 举报
回复
谢谢你们帮忙!但是我怎样给分呢?
王集鹄 2002-03-02
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
var
vSearchRec: TSearchRec;
LocalFileTime: TFileTime;
I: Integer;
begin
if FindFirst('autoexec.bat', faAnyFile, vSearchRec) = 0 then

FileTimeToLocalFileTime(vSearchRec.FindData.ftCreationTime, LocalFileTime);
FileTimeToDosDateTime(LocalFileTime, LongRec(I).Hi, LongRec(I).Lo);
Memo1.Lines.Values['创建时间'] := DateTimeToStr(FileDateToDateTime(I));

FileTimeToLocalFileTime(vSearchRec.FindData.ftLastAccessTime, LocalFileTime);
FileTimeToDosDateTime(LocalFileTime, LongRec(I).Hi, LongRec(I).Lo);
Memo1.Lines.Values['访问时间'] := DateTimeToStr(FileDateToDateTime(I));

FileTimeToLocalFileTime(vSearchRec.FindData.ftLastWriteTime, LocalFileTime);
FileTimeToDosDateTime(LocalFileTime, LongRec(I).Hi, LongRec(I).Lo);
Memo1.Lines.Values['修改时间'] := DateTimeToStr(FileDateToDateTime(I));
FindClose(vSearchRec);
end;
Bellamy 2002-03-02
  • 打赏
  • 举报
回复
用API!
eulb 2002-03-02
  • 打赏
  • 举报
回复

functionGetFileLastAccessTime(sFileName:string):TDateTime;
  var
  ffd:TWin32FindData;
  dft:DWord;
  lft:TFileTime;
  h:THandle;
  begin
  //getfileinformation
  h:ΚWindows.FindFirstFile(PChar(sFileName),ffd);
  if(INVALID—HANDLE—VALUEΙΛh)then

  begin
  //we′relookingforjustonefile,socloseour″find″
  Windows.FindClose(h);
  //converttheFILETIMEtolocalFILETIME
  FileTimeToLocalFileTime(ffd.ftLastAccessTime,lft);
  //convertFILETIMEtoDOStime
  FileTimeToDosDateTime(lft,LongRec(dft).Hi,LongRec(dft).Lo);
  //finally,convertDOStimetoTDateTimeforuseinDelphi′snativedate/timefunctions
  Result:ΚFileDateToDateTime(dft);
  end;
  end;
  GetFileLastAccessTime()将会以Delphi的TdateTime格式返回你所指定的文件的最后访问日期。

/////////////////////////////////////////////////////////
  某些软件需要获取文件的最后被访问时间,这一属性是DOS文件系统所没有的,无法用传统的函数来做到。Windows提供一个函数GetFileTime做此项操作,在Delphi中可方便地调用,示例如下:

procedure GetFileLastAccessTime(FileName: PChar);
var
CreateFT, LastAccessFT, LastWriteFT: TFileTime;
ST: TSystemTime;
F: Integer;
begin
{ 首先要用Windows的标准API函数以读方式打开文件 }
F := CreateFile(FileName, GENERIC_READ, 0,
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if F=INVALID_HANDLE_VALUE then begin

ShowMessage('Can not open file!');
Exit;
end;
{ 取文件时间 }
if GetFileTime(F, @CreateFT, @LastAccessFT, @LastWriteFT) then
begin
{ 转换为系统时间并显示 }
FileTimeToSystemTime(LastAccessFT, ST);
Label1.Caption := Format('%d-%d-%d, %d:%d:%d',
[ST.wYear, ST.wMonth, ST.wDay,
ST.wHour, ST.wMinute,ST.wSecond]);
end;
CloseHandle(F); // 记住关闭文件
end;

要获取文件夹中每个文件,可用API
FINDFIRSTFILE FINDNEXTFILE
caiyun 2002-03-02
  • 打赏
  • 举报
回复
GetFileTime
GetVolumeInformation
GetFileInformationByHandle

830

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧