删除IE临时文件夹下的所有文件,不知道为什么显示出来的列表之显示了一个文件~!!        private void button2_Click(object sender, EventArgs e)
        {
            //C:\Users\Admin\AppData\Local\Microsoft\Windows\Temporary Internet Files
            if (treeView1.Nodes.Count>0)
            {
                treeView1.Nodes.Clear();
            }
            treeView1.CheckBoxes = true;
            try
            {
                //开始扫描
                string[] files = Directory.GetFileSystemEntries(@"C:\Users\Admin\AppData\Local\Microsoft\Windows\Temporary Internet Files");
                foreach (string file in files)
                {
                    if (File.Exists(file))
                    {
                        treeView1.Nodes.Add(file);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

解决方案 »

  1.   

     DirectoryInfo folder = new DirectoryInfo(@"C:\Users\Admin\AppData\Local\Microsoft\Windows\Temporary Internet Files);
    foreach (FileInfo fi in folder.GetFiles("*.*"))
    {
     string fn = fi.Name;
    }
      

  2.   

    FindFirstUrlCacheEntryEx /FindNextUrlCacheEntryEx /DeleteUrlCacheEntry /FindCloseUrlCache
      

  3.   

    EmptyCache(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)));
    private void EmptyCache(DirectoryInfo folder) 

    foreach (FileInfo file in folder.GetFiles()) 

        //loop through each file in the folder and delete that 
        try 
        { 
            file.Delete(); 
        } 
        catch (Exception) 
        { //we have to use try cache, because there are some files that can’t be delete 
          // because those are system files. 
          // So we don’t want to stop our program at that point when our program try 
          // to delete any of those file and exception occurs 
        } 

    //loop through all the sub folder in the current folder provided 
    foreach (DirectoryInfo subfolder in folder.GetDirectories())
    {  
        EmptyCache(subfolder); 
    }} 来自
    http://howtoideas.net/how-to-clear-internet-cache-using-c
      

  4.   

    这有现在的清空IE缓存的API,某些情况下,循环枚举文件不一定能成功(权限问题或非IE外壳浏览器)