管理首页
quark(夸克)回复于 2002-04-03 14:15:14  win9x:   C:\WINDOWS\Favorites\           win2000:   D:\Documents   and   Settings\All   Users\Favorites\                用递归算法                递归算法实例:                //==============================================================================      //统计指定目录下指定类型文件数量(包括子目录)**********************************      //==============================================================================      function   GetFileCount(DirName,FileType:   string):   Integer;      var   DirInfo:   TSearchRec;              DosError:   Integer;      begin          Result   :=   0;          DosError   :=   FindFirst(DirName+'\*.*',   FaAnyfile,   DirInfo);          while   DosError=0   do          begin              if   ((DirInfo.Attr   and   FaDirectory)=faDirectory)   and   (DirInfo.Name<>'.')   and   (DirInfo.Name<>'..')              then   Result   :=   Result   +   GetFileCount(DirName   +   '\'   +   DirInfo.Name,   FileType);              {$IF   DEFINED(WIN32)   AND   DECLARED(UsingVCL)}              if   ((DirInfo.Attr   and   FaDirectory)<>FaDirectory)   and   ((DirInfo.Attr   and   FaVolumeID)<>FaVolumeID)              {$ELSE}              if   ((DirInfo.Attr   and   FaDirectory)<>FaDirectory)              {$IFEND}              then   if   Trim(FileType)='*.*'                        then   Inc(Result)                        else   if   Pos(UpperCase(Copy(FileType,Pos('*',FileType)+1,Length(FileType)-1)),UpperCase(DirInfo.Name))>0                                  then   Inc(Result);              DosError   :=   FindNext(DirInfo);          end;          SysUtils.FindClose(DirInfo);      end;         cg1120(代码最优化-§惟坚韧者始能遂其志§)回复于 2002-05-23 18:23:42 //读取URL文件内容      function   Tfrm_MainForm.GetUrlFileURL(FilePath,FileName:String):String;      Var          IniFile:TIniFile;      Begin          IniFile:=TIniFile.Create(FilePath+'\'+FileName);          Result   :=IniFile.ReadString('InternetShortcut','URL','about:blank');          IniFile.Free;      End;           //以下是递归取得收藏的所有目录和URL      procedure   Tfrm_MainForm.CreateFavoritesMenu(Const   WorkDir:String;Var   MenuItem:TMenuItem);      Var          SearchRec:TSearchRec;          FWorkDir:String;          SubMenuItem:TMenuItem;      begin          FWorkDir   :=WorkDir;          if   (FindFirst(FWorkDir   +'\*.*',   faDirectory,SearchRec)=0)   then          begin              repeat                  if   (SearchRec.Attr   and   faDirectory   =   faDirectory)   then                  Begin                      if   (SearchRec.Name   <>'.')and   (SearchRec.Name   <>'..')   then                      begin                          SubMenuItem:=TMenuItem.Create(Self);                          SubMenuItem.Caption   :=SearchRec.Name;                          MenuItem.Add(SubMenuItem);     //子目录                          CreateFavoritesMenu(FWorkDir+'\'+SearchRec.Name,SubMenuItem);                      end;                  end;              until   FindNext(SearchRec)   <>   0;          End;          FindClose(SearchRec);               if   (FindFirst(FWorkDir   +'\*.*',   faDirectory,SearchRec)=0)   then          begin              repeat                  if   (SearchRec.Attr   and   faDirectory   <>   faDirectory)   then                  Begin                      SubMenuItem:=TMenuItem.Create(MenuItem);                      SubMenuItem.Caption   :=Copy(SearchRec.Name,1,Length(SearchRec.Name)-4);                      if   Length(SubMenuItem.Caption)   >25   then                          SubMenuItem.Caption   :=Copy(SubMenuItem.Caption,1,25)+'...';                      SubMenuItem.Hint   :=GetUrlFileURL(FWorkDir,SearchRec.Name);                      SubMenuItem.OnClick   :=MenuItem_FaClick;                      MenuItem.Add(SubMenuItem);                  end;              until   FindNext(SearchRec)   <>   0;          End;          FindClose(SearchRec);           End;       hongfengbeauty(想和梦想比赛的人)回复于 2002-05-23 18:28:48  function   GetIEFavourites(const   favpath:   string):TStrings;        var            searchrec:TSearchrec;            str:TStrings;            path,dir,filename:String;            Buffer:   array[0..2047]   of   Char;            found:Integer;        begin          str:=TStringList.Create;          //Get   all   file   names   in   the   favourites   path          path:=FavPath+'\*.url';          dir:=ExtractFilepath(path);          found:=FindFirst(path,faAnyFile,searchrec);          while   found=0   do   begin            //Get   now   URLs   from   files   in   variable   files            SetString(filename,   Buffer,   GetPrivateProfileString('InternetShortcut',            PChar('URL'),   NIL,   Buffer,   SizeOf(Buffer),   PChar(dir+searchrec.Name)));            str.Add(filename);            found:=FindNext(searchrec);          end;          //unterordner   finden          found:=FindFirst(dir+'\*.*',faAnyFile,searchrec);          while   found=0   do   begin            if   ((searchrec.Attr   and   faDirectory)   >   0)   and   (searchrec.Name[1]<>'.')   then            str.AddStrings(GetIEFavourites(dir+'\'+searchrec.name));            found:=FindNext(searchrec);          end;          FindClose(searchrec);          Result:=str;        end;               procedure   TForm1.Button1Click(Sender:   TObject);        var   pidl:   PItemIDList;            FavPath:   array[0..MAX_PATH]   of   char;        begin          SHGetSpecialFolderLocation(Handle,   CSIDL_FAVORITES,   pidl);          SHGetPathFromIDList(pidl,   favpath);          ListBox1.Items:=GetIEFavourites(StrPas(FavPath));        end;
|