Board index » delphi » A program that remove specified lines in all htm-files in one directory

A program that remove specified lines in all htm-files in one directory

I want to make a program that search through all htm- files in one directory
and remove a specified string at the end of the htm- files.
Is this possible? I need it for a special task so I am very happy if
somebody could help me. I am a newbie so don't write advanced, please!

Thanks!!

 

Re:A program that remove specified lines in all htm-files in one directory


Hi!

Quote
> I want to make a program that search through all htm- files in one directory
> and remove a specified string at the end of the htm- files.
> Is this possible?

Sure.

get the html-files by using FindFirst / FindNext (this is a FAQ).
load them in a StringList.
search your string and remove it.
save the file.

small example:
var
   aList              : TStringList;
   SearchRec          : TSearchRec;
   Found,i            : Integer;
   directory,mystring : string;

begin
   Found := FindFirst(directory + mask, faAnyFile, SearchRec);
   while Found = 0 do
     begin
       aList:=TStringList.Create;
       try
       aList.LoadFromFile(directory + SearchRec.Name);
       for i:=0 to aList.lines.Count -1 do      
         begin
           if pos(mystring,aList.lines[i]) > 0 then
             // do what you want

         end;
       finally
         aList.free;
       Found := FindNext(SearchRec);
     end;
   FindClose(SearchRec);
end;

Stefan

Other Threads