语 种:简体中文
编辑器:Delphi6
平 台:Win9x,Win2k/XP/NT,Win2003
作品源代码: -
软件或演示: -
代码大小: -
软件大小: -
这个代码绝对原创,网上找的代码不是文件下不全,就是用不了。
代码可能还是有问题。请大家指正。谢谢。
function IsFileInUse(fName : string ):boolean; //检测文件是否正在使用
var
HFileRes : HFILE;
begin
Result := false;
if not FileExists(fName) then
exit;
HFileRes := CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE,0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
Result := (HFileRes = INVALID_HANDLE_VALUE);
if not Result then
CloseHandle(HFileRes);
end;
procedure TDownForm.DownLoadDir(LocalPath,ServERPath:string);
var
i,count1:integer;
att:TIdDirItemType;
FileList : TStrings;
Name{, Line}: String;
ss:string;
begin
try begin
FileList := TStringList.Create;
ChageDir(serverpath);
Application.ProcessMessages;
if AnsiLastChar(serverpath) <> '/' then
serverpath := serverpath '/';
if AnsiLastChar(localpath) <> '\' then
localpath := localpath '\';
if not DirectoryExists(localpath serverpath) then ForceDirectories(localpath serverpath);
IdFTP1.List(FileList);
Application.ProcessMessages;
count1:=IdFTP1.DirectoryListing.Count;
for i:=0 to count1-1 do begin
ss:=IdFTP1.DirectoryListing.Items[i].FileName;
att:=IdFTP1.DirectoryListing.Items[i].ItemType;
if (att<>ditDirectory) then begin
if not DirectoryExists(localpath serverpath) then ForceDirectories(localpath serverpath);
BytesToTransfer := IdFTP1.Size(ss);
if IsFileInUse(ss)=False then
IdFTP1.Get(ss,localpath serverpath ss,true)
else Exit;
Application.ProcessMessages;
lbl1.Caption:='已下载:' ss;
lbl1.Update;
end
end;
for i:=0 to count1-1 do begin
ss:=IdFTP1.DirectoryListing.Items[i].FileName;
att:=IdFTP1.DirectoryListing.Items[i].ItemType;
BytesToTransfer := IdFTP1.Size(ss);
if (att=ditDirectory) and (ss <> '.') AND (ss <> '..') then begin
Name := ss;
if not DirectoryExists(localpath serverpath Name) then ForceDirectories(localpath serverpath Name);
DownLoadDir(localpath serverpath,Name);
Application.ProcessMessages
end;
end;
ChageDir('..');//这句是返回前一个目录,写的另一个函数,可以用IdFTP1.ChangeDir替换
Filelist.Free;
end
except
end;
end;
上一篇: 每日一帖示例程序 (使用HTML格式)
下一篇: DMO Demo v0.01 (带进度条的备份)
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




