Thema: Delphi read from multiple Files

Einzelnen Beitrag anzeigen

mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: read from multiple Files

  Alt 25. Mär 2009, 20:09
I did it but that doesn't give me the result i'm looking for ( i want to load many files into the Stream ).

So what i did id :

Delphi-Quellcode:
Procedure Load(const AFilename: String);
var
  MS : TMemoryStream;
  FS : TFileStream;
  MyStringList:TStringList;
  i:integer;
begin
   MS := TMemoryStream.Create;
   MyStringList:=TStringList.Create;
   MyStringList.Add(AFilename);
try
  For i:=0 to MyStringList.Count-1 do
    if FileExists(MyStringList[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
.
.
.
}


for i:=0 to FilesList.Items.Count-1 do
Load(FilesList.Items[i]);
end;
  Mit Zitat antworten Zitat