// 写成一个递归,remotedir为远程路径,localdir为本地路径,fromtime为指定更新时间起点
procedure TForm.check(Const remotedir:string;const localdir:string;const fromtime:TDateTime);
VAR
LS: TStringList;
FileCount:Integer;
test:string;
beginLS := TStringList.Create;
ForceDirectories(localdir+'\'+datetostr(date)+remotedir);//在本地目录重构远程目录结构
FTPClient.ChangeDir(remotedir);
FTPClient.List(LS);for FileCount:=0 to LS.Count - 1 do
begin
//判断是否为目录
if (FTPClient.DirectoryListing.Items[FileCount].ItemType = ditDirectory) and (FTPClient.DirectoryListing.Items[FileCount].FileName<>'.') and (FTPClient.DirectoryListing.Items[FileCount].FileName<>'..') then
begin
//递归调用 check(remotedir+FTPClient.DirectoryListing.Items[FileCount].FileName,localpath,Original_Time);
end
else //文件,判断修改时间是否在在指定时间之后,如果是,则下载到相对应的本地目录下
if FTPClient.DirectoryListing.Items[FileCount].ModifiedDate>fromtime then
FTPClient.Get(FTPClient.DirectoryListing.Items[FileCount].FileName,localdir+'\'+datetostr(date)+remotedir+FTPClient.DirectoryListing.Items[FileCount].FileName,true,false);
end;end;运行时提示不能创建目录,请高手帮我看看问题出在哪。
另外小弟刚接触DELOHI,程序写的很不规范,希望哪位高手能帮忙美化下,分数不够再加。
procedure TForm.check(Const remotedir:string;const localdir:string;const fromtime:TDateTime);
VAR
LS: TStringList;
FileCount:Integer;
test:string;
beginLS := TStringList.Create;
ForceDirectories(localdir+'\'+datetostr(date)+remotedir);//在本地目录重构远程目录结构
FTPClient.ChangeDir(remotedir);
FTPClient.List(LS);for FileCount:=0 to LS.Count - 1 do
begin
//判断是否为目录
if (FTPClient.DirectoryListing.Items[FileCount].ItemType = ditDirectory) and (FTPClient.DirectoryListing.Items[FileCount].FileName<>'.') and (FTPClient.DirectoryListing.Items[FileCount].FileName<>'..') then
begin
//递归调用 check(remotedir+FTPClient.DirectoryListing.Items[FileCount].FileName,localpath,Original_Time);
end
else //文件,判断修改时间是否在在指定时间之后,如果是,则下载到相对应的本地目录下
if FTPClient.DirectoryListing.Items[FileCount].ModifiedDate>fromtime then
FTPClient.Get(FTPClient.DirectoryListing.Items[FileCount].FileName,localdir+'\'+datetostr(date)+remotedir+FTPClient.DirectoryListing.Items[FileCount].FileName,true,false);
end;end;运行时提示不能创建目录,请高手帮我看看问题出在哪。
另外小弟刚接触DELOHI,程序写的很不规范,希望哪位高手能帮忙美化下,分数不够再加。
procedure TForm.check(Const remotedir:string;const localdir:string;const fromtime:TDateTime);
VAR
LS: TStringList;
FileCount:Integer;
test:string;
begin
LS := TStringList.Create;
try
ForceDirectories(localdir+'\'+datetostr(date)+remotedir);//在本地目录重构远程目录结构
FTPClient.ChangeDir(remotedir);
FTPClient.List(LS); for FileCount:=0 to LS.Count - 1 do
begin
//判断是否为目录
if (FTPClient.DirectoryListing.Items[FileCount].ItemType = ditDirectory) and (FTPClient.DirectoryListing.Items[FileCount].FileName<>'.') and (FTPClient.DirectoryListing.Items[FileCount].FileName<>'..') then
begin
//递归调用
check(remotedir+FTPClient.DirectoryListing.Items[FileCount].FileName,localpath,Original_Time);
end
else
begin
//文件,判断修改时间是否在在指定时间之后,如果是,则下载到相对应的本地目录下
if FTPClient.DirectoryListing.Items[FileCount].ModifiedDate>fromtime then
FTPClient.Get(FTPClient.DirectoryListing.Items[FileCount].FileName,localdir+'\'+datetostr(date)+remotedir+FTPClient.DirectoryListing.Items[FileCount].FileName,true,false);
end;
end;
finally
//用完后释放
LS.Free;
end;
end;
目录不能创建自己调一下吧,找出出错的语句是哪个位置.
(多半是目录名错误)
VAR
LS: TStringList;
FileCount:Integer;
datestr:string;
begin
TRY
datestr:=datetostr(date);
LS := TStringList.Create;
ForceDirectories(localdir+'\'+datestr+remotedir);//½¨±¾µØĿ¼
FTPClient.ChangeDir(remotedir);
FTPClient.List(LS); for FileCount:=0 to LS.Count - 1 do
begin
if (FTPClient.DirectoryListing.Items[FileCount].FileName<>'.') and (FTPClient.DirectoryListing.Items[FileCount].FileName<>'..') then
begin
if (FTPClient.DirectoryListing.Items[FileCount].ItemType = ditDirectory) then
begin
if remotedir='\' then
check(remotedir+FTPClient.DirectoryListing.Items[FileCount].FileName,LocalPath,Original_Time)
else
check(remotedir+'\'+FTPClient.DirectoryListing.Items[FileCount].FileName,LocalPath,Original_Time);
end
else
if (FTPClient.DirectoryListing.Items[FileCount].ModifiedDate>fromtime) then
FTPClient.Get(FTPClient.DirectoryListing.Items[FileCount].FileName,localdir+'\'+datestr+remotedir+'\'+FTPClient.DirectoryListing.Items[FileCount].FileName,true,false);
end;
end;
//for Finally
LS.FREE;
end;
end;
现在的问题是递归过程没错误,循环过程出错,提示list indexs out of bounds.WHY?LIST不是释放了吗?