2005. augusztus 11., csütörtök

Read the content of Internet Explorer's "Favourites" folder


Problem/Question/Abstract:

I would like to read the Properties of all entries in 'My Favorites' folder which contains all the web sites (URLs) addresses used by Internet Explorer. I would like to read the addresses and save them in a database. It's easier to do in Netscape because Netscape uses an HTML file that can be parsed easily.

Answer:

Solve 1:

The favourites folder is not very special. It just has some additions to the visibility. This function gets the location of it (no final backslash):

uses
  ShlObj;

function FavouritesPath: string;
var
  FilePath: array[0..MAX_PATH] of char;
begin
  SHGetSpecialFolderPath(0, FilePath, CSIDL_FAVORITES, false);
  Result := FilePath;
end;

Then you can traverse this folder and search for all *.url files. This is done by FindFirst/ FindNext. Use a recursive procedure if you want the subfolders, too.

To get the shortcut from these files, you can use this function (BTW: This is how TIniFile reads a string):

function GetInternetShortCut(const Filename: string): string;
var
  Buffer: array[0..2047] of Char;
begin
  SetString(Result, Buffer, GetPrivateProfileString('InternetShortcut',
    PChar('URL'), nil, Buffer, SizeOf(Buffer), PChar(Filename)));
end;

Example:

GetInternetShortcut(FavouritesPath + '\OneOfMyFavourites.url')


Solve 2:

I'm not sure if SHGetSpecialFolderPath is available on all Win32 platforms. Alternatively, you can use:

function FavoritesPath: string;
var
  FilePath: array[0..MAX_PATH] of Char;
  IDL: PItemIDList;
begin
  Result := '';
  if Succeeded(SHGetSpecialFolderLocation(0, CSIDL_FAVORITES, IDL)) then
    if SHGetPathFromIDList(IDL, FilePath) then
      Result := FilePath;
end;

Nincsenek megjegyzések:

Megjegyzés küldése