delphi idftp 获取修改时间

来源:百度知道 编辑:UC知道 时间:2024/07/07 21:31:04
代码如下,通过IDFTP连接,获取文件的修改时间,可是修改时间获不到,显示1601年1月1日 8:00:00,请高手解答!

procedure TFTPTestForm.GetFileInfo;
var
i:integer;
Listit:Tlistitem;
DIRStr:string;
begin
lv1.Clear;
lbl7.Caption:='00';
subini:=Tinifile.Create(PChar(ExtractFilePath(paramstr(0))+'config.ini'));
with IdFTP1 do
begin
DIRStr:=RetrieveCurrentDir;
end;
for i:=1 to subini.ReadInteger('HIS_UPDATE','filenum',0) do
begin
//if formatdatetime('yyyy-mm-dd hh:nn:ss',mddate)>formatdatetime('yyyy-mm-dd hh:nn:ss',GetFileLastWriteTime(g_path+subsoft+'\'+subpath+filname)) then
begin
Listit:=lv1.Items.Add;
with Listit do
begin
Listit.ImageIndex:=0;
Listit.Caption:=subini.ReadString('UpDate_Files','filename'+inttostr(i),'login');
Listit.SubItems.Add(FormatDateTime

获取文件的修改时间你看看下面的方法能不能用:
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;