小弟急需delphi实现文件下载,从服务器上把文件夹A 拷贝到本地磁盘上,假设本地磁盘有一文件夹A,用服务器上的覆盖本地的 实现更新,A文件夹里面有子文件夹和文件有 源码吗,本人刚学DELPHI 。若有类似的让小弟看看也行!!在线急等,高分求
解决方案 »
- ASM中调用函数的几个问题
- 当Edit1的状态为Disable时,如何改变它的字体颜色
- Rem Objects开发三层的效率问题,用过的大侠帮帮忙,没用过的帮忙顶一下,谢谢
- ReportBuilder史上无法解决的问题,困扰我5年了
- 如何修改在ibgrid显示的数据
- 难:如何导出DLL中的Form?
- 这样的SQL语句怎样写, 是否非要分两步?
- 在线求助:一个dbgrid的问题,简单,都进来看看吧
- 各位高手。谁能帮小弟解决一个简单的问题~!感激不尽~!!!
- 弟兄们帮忙看一下,我看一了一个晚上都弄不明白为什么。
- 请问各位大虾:datasetExport是什么控件?还有alstatusbar又是什么系列控件?我查了半天查不出来!
- 用什么方法能够最快最稳定的下载
参考:TCopyFile = class(TThread)
public
Percent : Integer;
Done,ToDo : Integer;
ListIndex : integer;
Start : TDateTime;
constructor Create(Src, Dest: String);
private
{ Private declarations }
IName,OName : String;
protected
procedure Execute; override;
procedure CopyProgress;
procedure TotalCopyProgress;
procedure ShowError;
end;const
sc_DragMove:longint=$F012;
KB1 = 1024;
MB1 = 1024*KB1;
GB1 = 1024*MB1;
// ---------------------------
del_img_set=[22,24,25];
copy_img_set=[22,25];
var
CopyToForm: TCopyToForm;
iCopy,wid:integer;implementation
uses Main,ShellAPI,FileCtrl,FmxUtils,ShlObj,ActiveX;
{$R *.DFM}constructor TCopyFile.Create(Src, Dest : String);
begin
IName := Src;
OName := Dest;
Percent := 0;
Start := Now;
FreeOnTerminate := True;
inherited Create(True);
end;procedure TCopyFile.ShowError;
begin
CopyToForm.CopyListView.items[ListIndex].ImageIndex :=25;
ShowMessage('无法读取源文件'+IName+',此次拷贝将是不完整的,请以后再试。');
end;procedure TCopyFile.CopyProgress;
begin
with CopyToForm do
begin
//listview1.items[ListIndex].SubItems.BeginUpdate;
CopyListview.items[ListIndex].SubItems[0]:= inttostr(Percent)+'%';
if percent>=100 then CopyListview.items[ListIndex].ImageIndex :=24;
//label4.Caption := '已复制'+ inttostr(Round((ListIndex+1)/listview1.Items.Count*100))+'%';
//listview1.items[ListIndex].SubItems.EndUpdate;
end;
end;procedure TCopyFile.TotalCopyProgress;
begin
with CopyToForm do
begin
inc(iCopy);
label4.Caption := '已复制'+ inttostr(Round((iCopy)/CopyListview.Items.Count*100))+'%';
caption:='拷贝文件('+label4.Caption+')';
if iCopy=CopyListview.Items.Count then
begin
label4.Caption := '复制完成。';
BtnCancel.Caption :='关闭';
//speedbutton4.Enabled := false;
show;
CopyToForm.WindowState := wsNormal;
//listview1.items[ListIndex].SubItems.EndUpdate;
end;
end;
end;procedure TCopyFile.Execute;
var
fi,fo : TFileStream;
dod,did : Integer;
cnt,max : Integer;
begin
Start := Now;
//try
{ Open existing destination }
if fileexists(oName) then //断点续传!
begin
try
fo := TFileStream.Create(OName, fmOpenReadWrite);
except on EFOpenError do
begin
{CopyToForm.CopyListView.items[ListIndex].ImageIndex :=25;
ShowMessage('无法读取源文件'+OName+',此次拷贝将是不完整的,请以后再试。'); }
synchronize(ShowError);
exit;
end;
end;//end of try
fo.Position:=fo.size;
end
//except
{ otherwise Create destination }
else fo := TFileStream.Create(OName, fmCreate);
//end;
try
{ open source }
try
fi := TFileStream.Create(IName, fmOpenRead);
except on EFOpenError do
begin
synchronize(ShowError);
exit;
end;
end;//end of try try
{ synchronise dest en src }
cnt:= fo.Position;
fi.Position := cnt;
max := fi.Size;
ToDo := Max-cnt;
Done := 0;
did:=0; // zw
{ start copying }
Repeat
dod := KB1; // Block size
if cnt+dod>max then dod := max-cnt;
try
if dod>0 then did := fo.CopyFrom(fi, dod);
except on EReadError do
begin
{CopyToForm.CopyListView.items[ListIndex].ImageIndex :=25;
ShowMessage('无法读取源文件'+OName+',此次拷贝将是不完整的,请以后再试。');}
synchronize(ShowError);
exit;
end
end; // end of try
cnt:=cnt+did;
Percent := Round(Cnt/Max*100);
synchronize(CopyProgress);
Done := Done+did;
ToDo := Max;
until (dod=0) or (Terminated); finally
fi.free;
end;
finally
fo.free;
end;
synchronize(TotalCopyProgress);
end;这个方法实际上支持断点序传哟(用于局域网中文件复制时特别有用)