X
xinux11
Unregistered / Unconfirmed
GUEST, unregistred user!
我找了一段FTP上传夹的代码,还挺好用,不过我想修改一下就遇到困难了,请大家帮帮我。
原始程序中,例如我选中“abc”文件夹,他会自动在FTP服务器上创建一个abc 的文件夹(里面包括了子文件夹和所有的文件)。不过小弟不想在FTP上建abc文件夹本身,只想要里面的子文件夹和所有的文件。不知如何修改?
原始程序代码如下:
procedure TForm1.UpLoad(Remote_path,Local_path:string);
var strl1,strl2,strl3:TStringList;
sr: TSearchRec;
i,j,DirCount,FileCount:integer;
str:string;
begin
IdFTP1.ChangeDir(Remote_path);
DirCount:=0;FileCount:=0;
IdFTP1.MakeDir(Copy(Local_path,LastDelimiter('/',Local_path)+1,length(Local_path)));
if FindFirst(Local_path + '/*.*', faDirectory, sr) = 0 then
begin
strl1:=TStringList.Create;
repeat
if (sr.Attr = faDirectory) and(sr.Name<>'.') and (sr.Name<>'..') then
begin
strl1.Add(sr.Name);
Inc(DirCount);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
for i:=0 to DirCount-1 do
begin
UpLoad(Remote_path+'/'+Copy(Local_path,LastDelimiter('/',Local_path)+1,length(Local_path)),Local_path+'/'+strl1.Strings);
end;
if FindFirst(Local_path + '/*.*',faAnyFile, sr )=0 then
begin
strl2:=TStringList.Create;
repeat
if (sr.Attr <> faDirectory) then
begin
strl2.Add(sr.Name);
Inc(FileCount);
end;
until FindNext(sr) <>0;
FindClose(sr);
end;
IdFTP1.ChangeDir(Remote_path+'/'+Copy(Local_path,LastDelimiter('/',Local_path)+1,length(Local_path)));
for j:=0 to FileCount-1 do
begin
try
IdFTP1.Put(Local_path+'/'+strl2[j],IdFTP1.RetrieveCurrentDir+'/'+strl2[j]);
ListBox1.Items.Add('@_@ '+strl2[j]+'上传成功!');
except
ListBox1.Items.Add(' '+strl2[j]+'上传失败!');
Continue;
end;
end;
end;
原始程序中,例如我选中“abc”文件夹,他会自动在FTP服务器上创建一个abc 的文件夹(里面包括了子文件夹和所有的文件)。不过小弟不想在FTP上建abc文件夹本身,只想要里面的子文件夹和所有的文件。不知如何修改?
原始程序代码如下:
procedure TForm1.UpLoad(Remote_path,Local_path:string);
var strl1,strl2,strl3:TStringList;
sr: TSearchRec;
i,j,DirCount,FileCount:integer;
str:string;
begin
IdFTP1.ChangeDir(Remote_path);
DirCount:=0;FileCount:=0;
IdFTP1.MakeDir(Copy(Local_path,LastDelimiter('/',Local_path)+1,length(Local_path)));
if FindFirst(Local_path + '/*.*', faDirectory, sr) = 0 then
begin
strl1:=TStringList.Create;
repeat
if (sr.Attr = faDirectory) and(sr.Name<>'.') and (sr.Name<>'..') then
begin
strl1.Add(sr.Name);
Inc(DirCount);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
for i:=0 to DirCount-1 do
begin
UpLoad(Remote_path+'/'+Copy(Local_path,LastDelimiter('/',Local_path)+1,length(Local_path)),Local_path+'/'+strl1.Strings);
end;
if FindFirst(Local_path + '/*.*',faAnyFile, sr )=0 then
begin
strl2:=TStringList.Create;
repeat
if (sr.Attr <> faDirectory) then
begin
strl2.Add(sr.Name);
Inc(FileCount);
end;
until FindNext(sr) <>0;
FindClose(sr);
end;
IdFTP1.ChangeDir(Remote_path+'/'+Copy(Local_path,LastDelimiter('/',Local_path)+1,length(Local_path)));
for j:=0 to FileCount-1 do
begin
try
IdFTP1.Put(Local_path+'/'+strl2[j],IdFTP1.RetrieveCurrentDir+'/'+strl2[j]);
ListBox1.Items.Add('@_@ '+strl2[j]+'上传成功!');
except
ListBox1.Items.Add(' '+strl2[j]+'上传失败!');
Continue;
end;
end;
end;