http://topic.csdn.net/u/20120314/20/5c2b87bb-b5ff-4f16-9f64-bb59c2be9be3.html
以前提问过一次,但是无解。现在若有人能解决,一并结贴。之前遗留的问题是,普通的文件夹里可以正常取得,但是IE临时文件夹就不行,不知道有什么特殊性?能解决此问题的高手请加我扣扣:一零九九七三。200分都给你,另用淘宝转账100RMB!谢谢。

解决方案 »

  1.   

    为了100块。 费了半天的劲。试出来了。嘿嘿。
    用 FindFirst, FindNext 递归一下,就能找到。
    你找不到的原因,我知道了。因为这个图片在IE下载后。就从a.jpg 变成 a[1].jpg了
    unit Main;interfaceuses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Masks;type
      TForm3 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        Edit1: TEdit;
        Edit2: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        function FindMyFile(const FilePath, FileName: string): integer;
      public
        { Public declarations }
      end;var
      Form3: TForm3;
    var
      myFileName, myFileExt: string;
    implementationuses Registry;{$R *.dfm}function GetIeTempFilePath(): string;
    var reg: Tregistry;
      KeyList: TStringList;
      i: Integer;
    begin
      reg := Tregistry.create;
      KeyList := TStringList.Create;
      reg.RootKey := HKEY_CURRENT_USER;
      reg.openkey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', False);
      reg.GetValueNames(KeyList);
      for i := 0 to KeyList.Count - 1 do
      begin
        if KeyList[i] = 'Cache' then
        begin
          Result := reg.ReadString(KeyList[i]);
          Exit;
        end;
      end;
      reg.CloseKey;
      reg.free;
      KeyList.Free;
    end;function TForm3.FindMyFile(const FilePath, FileName: string): integer;
    var
      sr: TSearchRec;
    begin
      Result := -1;
      if FindFirst(FilePath + '\*.*', faAnyFile, sr) = 0 then
      begin
        repeat
          if(sr.Name <> '.') and (sr.Name <> '..') then
            if (FileGetAttr(FilePath + '\' + sr.Name) and faDirectory) = faDirectory then
            begin
              FindMyFile(FilePath + '\' + sr.Name, FileName);
            end
            else
            begin
              //Memo1.Lines.Add(Format('%20s - %d', [FilePath + '\' + sr.Name, sr.Size]));
              if ExtractFileExt(sr.Name) = myFileExt then
                if Pos(UpperCase(FileName), UpperCase(sr.Name)) > 0 then
                begin
                  Memo1.Lines.Add(Format('%20s - %d', [FilePath + '\' + sr.Name, sr.Size]));
                  Result := sr.Size;
                  Break;
                end;
            end;
        until FindNext(sr) <> 0;
      end;
      FindClose(sr);
    end;procedure TForm3.Button1Click(Sender: TObject);
    var
      filePath: string;
    begin
      filePath := GetIeTempFilePath;
      Memo1.Clear;
      myFileName := Edit1.Text;
      myFileExt := Edit2.Text;
      FindMyFile(filePath, myFileName);
      ShowMessage('查找完成');
    end;end.
      

  2.   

    4楼哥们已加我Q联系,完美解决我要的功能,并且还送了一个功能,十分感谢,另外也谢谢2楼的朋友,只不过来晚一步。抱歉!钱已转给ansinlee,期待下次继续合作!
      

  3.   

    4楼:
    为了100块。 费了半天的劲。试出来了。嘿嘿。
    用 FindFirst, FindNext 递归一下,就能找到。
    你找不到的原因,我知道了。因为这个图片在IE下载后。就从a.jpg 变成 a[1].jpg了没想到是这样啊!我是引用了.net的api才找到的,可以进行操作,还查了半天msn,不过拼音都忘光了,拼了好半天才明白怎么用……
    还是2楼聪明!