大家好,我想问在D7下如何用INDY组件实现整个文件夹的上传?谢谢

解决方案 »

  1.   

    这是我自己写的上传文件夹功能,写成了一个函数
    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[i]);//这里实现递归调用
      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(':o   '+strl2[j]+'上传失败!');
          Continue;
        end;
      end;
    end;
    调用:
    UpLoad(Form1.IdFTP1.RetrieveCurrentDir,Form1.ShellListView1.SelectedFolder.PathName);
      

  2.   

    都是逐个文件来的http://lysoft.7u7.net