Код: Выделить всё
Function getFileSize( FPath:String):Int64;
var
sr: TSearchRec;
S: string;
HTTPClient : TFPHttpClient;
ST:TStringList;
begin
Result := -1;
If pos('http',FPath)=1 then begin
HTTPClient := TFPHttpClient.Create(nil);
ST:=TStringList.Create;
try
HTTPClient.Head(FPath,ST);
except
HTTPClient.Free;
St.Free;
exit;
end;
if HTTPClient.ResponseStatusText='' then begin
S:= HTTPClient.GetHeader(ST,'Content-Length');
If S<>'' then Result := S.ToInt64;
end;
HTTPClient.Free;
St.Free;
end else
begin
try
if FindFirst(FPath , faAnyFile, sr) = 0 then
begin
Result := Sr.Size;
end
finally
FindClose(sr);
end
end
end;
