Thema: Delphi read from multiple Files

Einzelnen Beitrag anzeigen

Muetze1
(Gast)

n/a Beiträge
 
#5

Re: read from multiple Files

  Alt 26. Mär 2009, 08:31
Hi!

In your Load function, you create a new stringlist. Then you just add one filename to this stringlist. After this, you iterate through all items of the stringlist (everytime just one) and you are wondering why it is still just one entry?

Delphi-Quellcode:
Procedure Load(const AFilenames: TStrings);
var
  MS : TMemoryStream;
  FS : TFileStream;
  i:integer;
begin
  MS := TMemoryStream.Create;
  try
    For i:=0 to AFilenames.Count-1 do
    begin
      if FileExists(AFilenames[i]) then
      begin
        FS := TFileStream.Create(MyStringList[i], fmOpenRead or fmShareDenyNone);
        try
          MS.CopyFrom(FS, FS.Size);
        finally
          FS.Free;
        end;
      end;
  finally
      // All the MS contents will be saved to Res.txt as an example
    MS.SaveToFile('Res.txt');
    MS.Free;
  end;
end;
Delphi-Quellcode:
// as an example how to use it
procedure TForm1.Button1Click(Sender: TObject);
var
  i:integer;
begin
  {FilesList : is a TListBox
  items[0]:=c:\001.txt
  items[1]:=c:\002.txt
  .
  .
  .
    }


  Load(FilesList.Items);
end;
  Mit Zitat antworten Zitat