忘不了你的温柔刘冲mp3:通过读文件方式获得收藏夹中URL

来源:百度文库 编辑:中财网 时间:2024/05/03 09:25:21

通过读文件方式获得收藏夹中URL

分类: Delphi 2008-09-11 13:21 270人阅读 评论(0) 收藏 举报
  1. {*******************************************************}
  2. {                                                       }
  3. {       通过读文件方式获得收藏夹中URL                   }
  4. {                                                       }
  5. {       版权所有 (C) 2008 QQ:3150379                   }
  6. {                                                       }
  7. {*******************************************************}
  8. unit Unit1;
  9. interface
  10. uses
  11.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  12.   Dialogs, StdCtrls, IniFiles, ShlObj;
  13. type
  14.   TForm1 = class(TForm)
  15.     btn1: TButton;
  16.     Memo1: TMemo;
  17.     procedure btn1Click(Sender: TObject);
  18.   private
  19.   public
  20.     { Public declarations }
  21.   end;
  22. var
  23.   Form1: TForm1;
  24. implementation
  25. {$R *.dfm}
  26. { TForm1 }
  27. //------------------------------------------------------------------------------
  28. // 通过读文件方式获得收藏夹中URL
  29. //------------------------------------------------------------------------------
  30. procedure TForm1.btn1Click(Sender: TObject);
  31.   function GetFavoritesUrl(FavoritesFile: string): string;
  32.   var
  33.     MyIniFile: TInifile;
  34.   begin
  35.     MyIniFile := TInifile.Create(FavoritesFile);
  36.     try
  37.       Result := MyIniFile.ReadString('InternetShortcut', 'URL', '');
  38.     finally
  39.       MyIniFile.Free;
  40.     end;
  41.   end;
  42. var
  43.   Search: TSearchRec;
  44.   pidl: PItemIDList;
  45.   FavPath: array[0..MAX_PATH] of char;
  46.   FavoritesPath: string;
  47.   i, j: Integer;
  48. begin
  49.   SHGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl);
  50.   SHGetPathFromIDList(pidl, @FavPath);
  51.   FavoritesPath := Format('%s/', [FavPath]);
  52.   Memo1.Clear;
  53.   with Search, Memo1.Lines do
  54.   begin
  55.     i := FindFirst(FavoritesPath + '*.url', 0, Search);
  56.     j := 1;
  57.     while i = 0 do
  58.     begin
  59.       if (Search.Name <> '.') and (Search.Name <> '..') then
  60.       begin
  61.         Add(IntToStr(j) + '、' + Name);
  62.         Add('    ' + GetFavoritesUrl(FavoritesPath + Name));
  63.         SetLength(Name, Length(Name) - 4);
  64.         i := FindNext(Search);
  65.         j := j + 1;
  66.       end;
  67.     end;
  68.   end;
  69. end;
  70. end.