我需要扫描特定文件夹中的最新文件(基本上检查修改日期以查看哪个是最新的),但请记住,文件具有随机名称.这是我到目前为止所得到的: procedure TForm1.Button1Click(Sender: TObject);beginftp.H
procedure TForm1.Button1Click(Sender: TObject);
begin
ftp.Host := 'domain';
ftp.Username := 'username';
ftp.password := 'password';
ftp.Connect;
ftp.Put('random-filename.ext'); //This is where it should grab only the latest file
ftp.Quit;
ftp.Disconnect;
end;
这可能吗?
谢谢!
假设OP想要扫描特定的本地文件夹并找到最新修改的文件,这里有一个非常简单的功能:function GetLastModifiedFileName(AFolder: String; APattern: String = '*.*'): String;
var
sr: TSearchRec;
aTime: Integer;
begin
Result := '';
aTime := 0;
if FindFirst(IncludeTrailingPathDelimiter(AFolder) + APattern, faAnyFile, sr) = 0 then
begin
repeat
if sr.Time > aTime then
begin
aTime := sr.Time;
Result := sr.Name;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
AFolder应该是您要扫描的文件夹的绝对路径或相对路径,APattern是可选的,应该包含指定应检查哪些文件的标准DOS模式.如果没有为第二个参数指定任何内容,则假定为*.*(所有文件).结果将是具有最近修改日期的文件名.
