Advertisement
lpciprian

Lazarus XML editor (creating a new line from an existing file path string)

Sep 5th, 2023
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.55 KB | Source Code | 0 0
  1. procedure Gaseste(const fileName, searchText,ext: string;var nr:integer);   //procedure to find every game in the list
  2. var                               //search will include parameters: file name, file extension
  3.   sl: TStringList;
  4.   i: Integer;
  5.   NumeleImaginii:string;        //image name
  6. begin
  7.   sl := TStringList.Create;
  8.   nr:=0;
  9.   try
  10.     sl.LoadFromFile(fileName);    //loading string list from file
  11.     NumeleImaginii:='';
  12.     for i := sl.Count-1 downto 0 do
  13.     begin
  14.       if Pos(searchText, sl[i])<>0 then    //for every line we look for a string of interest containing searchText
  15.       begin
  16.         NumeleImaginii:=sl[i].Remove(0,18); //delete from file path the first characters: <path>./
  17.                                              //I will use sl[i].Delete. For some reason removing 18 characters from the string
  18.                                              //results in less characters removed
  19.         Form1.Caption:=Form1.Caption+' '+NumeleImaginii;  //just checking what I deleted from my string
  20.        
  21.         NumeleImaginii:=NumeleImaginii.Remove(NumeleImaginii.Length-11,11);   //delete from file path the last 10 characters
  22.                                                                               //that also include file extension ***</path>
  23.        
  24.  
  25.         sl.Insert(i,'        <image>./Covers/'+NumeleImaginii+'.png</image>'); //insert the image name in the XML
  26.         nr:=nr+1;
  27.         //sl.Delete(i);
  28.       end;
  29.     end;
  30.     sl.SaveToFile(fileName+'.edit');     //saving filename.edit
  31.   finally
  32.     sl.Free;
  33.   end;
  34. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement