Searching for favourites
Uses TSearchRec to loop through the Explorer favourites, which really are inifiles. Result is beeing placed in HTML and text files.
NOTE: This article is a couple of years old. And while the code still works fine as an example of using inifiles and recursive searches - Internet Explorer has had export possibilities built into the program.
**
Collecting Explorer Favourites
Johan Lindgren
Recently a person at work was leaving for another company. Beeing a journalist, she was very interested in bringing the long list of favourite internet links that she had collected during her time with us. This is really a valueble journalistic tool these days. Well, if she were going to a company also equiped with Windows and Explorer you could simply copy the folder holding the favourites. But since she was going to a MAC-based company using Netscape it was a different situation. There might be a way in Explorer to do this. And there might be programs out there doing this. But I found none so I did a program to do it. What the program does is simply recursively search the folder with the Explorer favourites and adding it all to a textfile and a HTML-file. The big advantage with storing the result in the HTML-format is that you can make the links active and thus the file useful in any browser.
First of all there is an ini-file with settings for the searchpath to the favourites and the searchpath and names of the files where the result is to be stored. The file is named "favoriter.ini" and is placed in the same folder as the exe-file. (Some words you encounter are in Swedish!)
The inifile:
[Favoriter]
WindowsFavoriter=c:\windows\favoriter\
HTMLsave=c:\favoriter.html
TEXTsave=c:\favoriter.txt
It is important to get the search path right for the program to work.
The program consist of a richedit to hold the text result, a button to start, a button to close and a status bar. (Which is not necessary at all.)
The operation is pretty straight forward. When you click the start button the code attached to that button is executed. The search starts and if a subfolder is encountered a separate procedure is called. This procedure is recalled for each subfolder encountered. So the program will search out every subfolder.
This is search block from the click event. The routine in the procedure is very similar. (See the complete program listing.)
test := FindFirst(sokmapp+'*.*', faAnyFile, SearchRec); //See if we get any result from our first search
if test = 0 then //if we got a result. Indicated by a 0 in the FindFirst function!!
while test = 0 do begin //As long as we get 0's from our Searches there are more files or folders to process
case searchrec.Attr of //Check to see what attribute the searchresult had
16 : begin //If it was a 16 it is a sub folder
if (searchrec.name <> '.') and (searchrec.name <> '..') then //Check to see that it is not a . or a .. which are symbols for the folder above and the same folder
SokIEnMapp (sender,sokmapp+'\'+searchrec.name,searchrec.name); //If it was another folder, call a subroutine to investigate that folder
end;
32 : begin //If it was a 32 it is a file
if ansilowercase(extractfileext(searchrec.name)) = '.url' then begin //if the file name ends with .url it is an explorer favourite
inifil := tinifile.create (sokmapp+searchrec.name); //Create an inifile object for this file
try
temptext :=inifil.readstring ('InternetShortcut','URL',''); //Read the actual link from the file
richedit1.Lines.Add (stringreplace(searchrec.name,extractfileext(searchrec.name),'')+'='+temptext);//Show the file name and the link in the richedit
statusbar1.SimpleText := searchrec.name; //Show the filename in the status bar
statusbar1.Update; //Update the status bar
application.processmessages; //And give windows a chance to catch up
grunder.Add (''+stringreplace(searchrec.name,extractfileext(searchrec.name),'')+''); //Add the favourite to our temporary stringlist
finally
inifil.Free; //Free the inifile object
end;
end;
end;
end;
test := findnext(searchrec); //Call findnext to see if there are more files or folders
end;
findclose(searchrec); //Release the search object
The resulting HTML-file contains the name of the link and the actual link in a
Internet Favourites');//Set up the first HTML elements in that stringlist
try
test := FindFirst(sokmapp+'*.*', faAnyFile, SearchRec); //See if we get any result from our first search
if test = 0 then //if we got a result. Indicated by a 0 in the FindFirst function!!
while test = 0 do begin //As long as we get 0's from our Searches there are more files or folders to process
case searchrec.Attr of //Check to see what attribute the searchresult had
faDirectory : begin //If it was a 16 it is a sub folder
if (searchrec.name <> '.') and (searchrec.name <> '..') then //Check to see that it is not a . or a .. which are symbols for the folder above and the same folder
SokIEnMapp (sender,sokmapp+'\'+searchrec.name,searchrec.name); //If it was another folder, call a subroutine to investigate that folder
end;
32 : begin //If it was a 32 it is a file
if ansilowercase(extractfileext(searchrec.name)) = '.url' then begin //if the file name ends with .url it is an explorer favourite
inifil := tinifile.create (sokmapp+searchrec.name); //Create an inifile object for this file
try
temptext :=inifil.readstring ('InternetShortcut','URL',''); //Read the actual link from the file
richedit1.Lines.Add (stringreplace(searchrec.name,extractfileext(searchrec.name),'')+'='+temptext);//Show the file name and the link in the richedit
statusbar1.SimpleText := searchrec.name; //Show the filename in the status bar
statusbar1.Update; //Update the status bar
application.processmessages; //And give windows a chance to catch up
grunder.Add (''+stringreplace(searchrec.name,extractfileext(searchrec.name),'')+''); //Add the favourite to our temporary stringlist
finally
inifil.Free; //Free the inifile object
end; //try finally
end; //if .url
end;//case 32
end; //case
test := findnext(searchrec); //Call findnext to see if there are more files or folders
end; //while
findclose(searchrec); //Release the search object
htmlspar.Text := htmlspar.text + 'Various links';//Add to the HTML stringlist a header line and the results from this folder
htmlspar.add ('