CONST LocalPath='D:\TEST'
procedure TInVisibleForm_F.DoDownload(Path: string);
var
i,Found:Integer;
StrArr:TStringDynArray;
MtStr:string;
MtDate:TDateTime;
SR:TSearchRec;
DirCount:Integer;
begin
idftp.List;
DirCount:=idftp.DirectoryListing.Count;
for I :=0 to DirCount-1 do
begin
if Pos('D:',Path)=0 then
LocalPath:=LocalPath+'\'+Path;
if DirCount <> idFTP.DirectoryListing.Count then
begin
repeat
idFTP.ChangeDirUp;
idFTP.List(nil);
until DirCount = idFTP.DirectoryListing.Count ;
end;
if idftp.DirectoryListing.Items[i].ItemType=ditDirectory then
begin
idftp.ChangeDir(idftp.DirectoryListing.Items[i].FileName);
DoDownload(idftp.DirectoryListing.Items[i].FileName);
end
else
begin
if not DirectoryExists(LocalPath) then
FileOperate.Directory.CreateDirectory(LocalPath);
if FileExists(LocalPath+'\'+idftp.DirectoryListing.Items[i].FileName) then
begin
Found:=FindFirst(LocalPath+'\'+idftp.DirectoryListing.Items[i].FileName,faAnyFile,SR);
while Found=0 do
begin
MtStr:=FormatDateTime('yyyy-mm-dd hh:mm:ss',idftp.DirectoryListing.Items[i].ModifiedDate);
MtDate:=StrToDateTime(MtStr);
if FileOperate.CovFileDate(SR.FindData.ftLastWriteTime)<MtDate then
begin
if SR.Name<>'SmartDownLoad.exe' then
idftp.Get(idftp.DirectoryListing.Items[i].FileName,LocalPath+'\'+SR.Name,true);
end;
Found:=FindNext(SR);
end;
end
else
begin
if SR.Name<>'SmartDownLoad.exe' then
idftp.Get(idftp.DirectoryListing.Items[i].FileName,LocalPath+'\'+idftp.DirectoryListing.Items[i].FileName,True);
end;
end;
end;
end;递归调用的时候下载文件路径老是不对
比如服务器上有文件夹1\2\3\4\5,里面还有些文件
然后下到我硬盘里的路径会变成1\2\3\1\2\4\5,或者其他模样的
请问我的代码该怎么调整
begin
t:=tt.items[j];
if IdFTP.DirectoryListing.Items[j].ItemType = ditfile then //如果是文件
begin
if Length(t.FileName)<11 then name :='data.txt'
else name:=t.FileName;
try
IdFTP.Get(t.FileName ,ip.text+'\'+ftp_date.Text+'\'+name,True);
except
end;
end;
end;谁知道 如果该循环有1000次会经常导致无响应。