delphi检测远程文件是否存在

来源:百度知道 编辑:UC知道 时间:2024/07/08 16:09:11
delphi 如何检测网站文件是否存在 比如http://ftp-dg.pconline.com.cn/pub/download/200803/sogou_pinyin_green_35.rar
如何才能返回它是否存在
我可以用检测URL的方式来实现这一功能,但速度太慢了
有没有其它方法,比如通过idhttp之类的

使用TIdHTTP控件
try
IdHTTP.Head(URL);
except
showmessage('未连接到Internet或者文件不存在!');
end;

hg:thttpget;
begin
hg:=thttpget.Create(self);
hg.BinaryData:=true;
hg.UseCache:=false;
hg.FileName:='文件名';
hg.URL:=‘网址’;
hg.OnProgress:=onp;
hg.OnDoneFile:=ond;
hg.GetFile;
end;
procedure TForm1.ond(Sender: TObject; FileName: string; FileSize: Integer);
begin
pb.Position:=0;
if fileexists(getcurrentdir+'\Upx.zip')=false then
showmessage('不存在')
end;

这个检测很快,如果你下载的文件不存在,5秒左右就检测出来了。如果存在就会下载下来的。

ajax很快。
知道怎么用不?
var xmlhttp:olevariant;

xmlhttp:=createoleobject('Microsoft.XMLHTTP');
xmlhttp.open('GET','地址',false);
xmlhttp.send(nil);
然后判断返回值就可以了