uses ShellApi
procedure TForm1.Button2Click(Sender: TObject);
var FileOP:TSHFILEOPSTRUCT;
var P:Pchar;
begin
    GetMem(P,200);
    GetTempPath(200,p);
    FileOp.wnd:=Handle;
    FileOp.wFunc:=FO_Delete;
    FileOp.pFrom:=p;
    FileOp.fFlags:=FOF_ALLOWUNDO;
    //这个参数参考MSDN
    FileOp.hNameMappings:=nil;
    FileOp.lpszProgressTitle:=nil;
    SHFileOperation(FileOp);
end;
这个是删除临时文件夹。

解决方案 »

  1.   

    删除临时文件可以使用API函数:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Wininet, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        ListBox1: TListBox;
        ListBox2: TListBox;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        function FindNextEntrys(Handle:Integer):Boolean;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}
    function TForm1.FindNextEntrys(Handle:Integer):Boolean;
    var
      T: PInternetCacheEntryInfo;
      D: DWORD;
    begin
      D := 0;
      FindnextUrlCacheEntryEx(Handle, nil, @D, nil, nil, nil);
      GetMem(T, D);
      try
        if FindNextUrlCacheEntryEx(Handle, T, @D, nil, nil, nil) then begin
          ListBox1.Items.Add(T.lpszSourceUrlName);
          ListBox2.Items.Add(T.lpszLocalFileName);
          Result := True;
        end
        else
          Result := False;
      finally
        FreeMem(T, D)
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      H:Integer;
      T: PInternetCacheEntryInfo;
      D: DWORD;
    begin
      D := 0;
      FindFirstUrlCacheEntryEx(nil, 0, NORMAL_CACHE_ENTRY, 0,nil,@D, nil, nil, nil);
      GetMem(T, D);
      try
        H := FindFirstUrlCacheEntryEx(nil,0, NORMAL_CACHE_ENTRY, 0, T, @D, nil, nil, nil);
        if (H = 0) then
        else begin
          repeat
          until not FindNextEntrys(H);
          FindCloseUrlCache(H);
        end
      finally
        FreeMem(T, D)
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      URL:String;
    begin
      If ListBox1.ItemIndex >=0 then begin
        URL:=ListBox1.Items.Strings[ListBox1.ItemIndex];
        Self.Caption := URL;
        if DeleteUrlCacheEntry(PChar(URL))then
          ListBox1.Items.Delete(ListBox1.ItemIndex);
      end;
    end;end.    运行程序,点击Button1,就可以分别在ListBox1中列出所有在Cache中的文件所对应的URL以及在ListBox2中列出相应的文件名。在ListBox1中选择一个列表,然后点击 Button2 就可以将该项从Cache中删除。删除历史列表需要使用IUrlHistoryStg 接口, 我的主页有一个VB的范例
      

  2.   

    哈哈;有那么复杂嘛!!!;现获取windows目录(不许问我怎么做),然后……;
    删除windows\Favorites所有文件;
    删除windows\Temp所有文件;ok?;
      

  3.   

    关于操作历史纪录,这里:http://www.euromind.com/iedelphi/urlhistory.htm
    有一个带源代码的组件下载。利用的就是IURLHistorySTG接口。
    如果你想直接利用删除文件的方法也可以,但是需要使用SHGetSpecialFolderLocation获得临时文件目录以及历史文件夹目录而不应该简单的指定 Windows目录+History什么的,Windows2000以及9x下的存放目录是不一样的,而且用户可疑修改,例如我的临时文件目录就在h:\internet Temp下
      

  4.   

    跟我上面的程序合在一起,就可以完成你的要求!哈哈。
    procedure TForm1.Button1Click(Sender: TObject);
    var P:PChar;
     var FileOP:TSHFILEOPSTRUCT;
    begin
            GetMem(P,200);
            SHGetSpecialFolderPath(0,p,CSIDL_COMMON_FAVORITES,False);
            ShowMessage(Strpas(P));
        FileOp.wnd:=Handle;
        FileOp.wFunc:=FO_Delete;
        FileOp.pFrom:=p;
        FileOp.fFlags:=FOF_ALLOWUNDO;
        //这个参数参考MSDN
        FileOp.hNameMappings:=nil;
        FileOp.lpszProgressTitle:=nil;
        SHFileOperation(FileOp);
    end;
      

  5.   

    可用通过注册表获得,收藏夹目录其实很简单的!!!干吗搞那么复杂
    //获得系统Cache文件夹函数如History、Cache、Rencent、Cookies
    function  GetSystemDir(const Volume :string):String;
    var
      Reg : TRegistry;
    begin
        Reg:=TRegistry.Create;
        try
         Reg.RootKey:=HKEY_CURRENT_USER;
           Reg.Openkey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',False);
           Result:=Reg.ReadString(Volume);
        finally
           Reg.CloseKey;
           Reg.Free;
        end;
    end;……
    DelAllFiles(GetSystemDir('Cookies'));
          //删除Cache文件
          Deltree(GetSystemDir('Cache'));
          GetCurrentDir;
          CreateDir(GetSystemDir('Cache'));
    df
      

  6.   

    deltree(GetSystemDir('Favorites');
    GetCurrentDir;
    CreateDir(GetSystemDir('Favorites'));
    ……
    其实就这么简单,高手们干吗用那么负责的办法了,无异于用高射炮打蚊子
      

  7.   

    请教 duducat(嘟嘟猫) 
    deltree是自定义函数还是系统函数
      

  8.   

    to :  ch81(missile)
    提示信息:删除文件或文件夹时出错
        无法删除文件,无法读源文件或磁盘
    该怎样避免这个错误