删除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);
}
}
{
//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);
}
}
foreach (FileInfo fi in folder.GetFiles("*.*"))
{
string fn = fi.Name;
}
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