- {*******************************************************}
- { }
- { 通过读文件方式获得收藏夹中URL }
- { }
- { 版权所有 (C) 2008 QQ:3150379 }
- { }
- {*******************************************************}
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, IniFiles, ShlObj;
- type
- TForm1 = class(TForm)
- btn1: TButton;
- Memo1: TMemo;
- procedure btn1Click(Sender: TObject);
- private
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- { TForm1 }
- //------------------------------------------------------------------------------
- // 通过读文件方式获得收藏夹中URL
- //------------------------------------------------------------------------------
- procedure TForm1.btn1Click(Sender: TObject);
- function GetFavoritesUrl(FavoritesFile: string): string;
- var
- MyIniFile: TInifile;
- begin
- MyIniFile := TInifile.Create(FavoritesFile);
- try
- Result := MyIniFile.ReadString('InternetShortcut', 'URL', '');
- finally
- MyIniFile.Free;
- end;
- end;
- var
- Search: TSearchRec;
- pidl: PItemIDList;
- FavPath: array[0..MAX_PATH] of char;
- FavoritesPath: string;
- i, j: Integer;
- begin
- SHGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl);
- SHGetPathFromIDList(pidl, @FavPath);
- FavoritesPath := Format('%s/', [FavPath]);
- Memo1.Clear;
- with Search, Memo1.Lines do
- begin
- i := FindFirst(FavoritesPath + '*.url', 0, Search);
- j := 1;
- while i = 0 do
- begin
- if (Search.Name <> '.') and (Search.Name <> '..') then
- begin
- Add(IntToStr(j) + '、' + Name);
- Add(' ' + GetFavoritesUrl(FavoritesPath + Name));
- SetLength(Name, Length(Name) - 4);
- i := FindNext(Search);
- j := j + 1;
- end;
- end;
- end;
- end;
- end.